Skip to content

Commit 59983cd

Browse files
committed
Added functionality to get custom post types
1 parent 8b781ce commit 59983cd

File tree

2 files changed

+16
-9
lines changed

2 files changed

+16
-9
lines changed

src/main/java/com/afrozaar/wordpress/wpapi/v2/Client.java

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -187,8 +187,8 @@ public Post createPost(Post post, PostStatus status) throws PostCreateException
187187
}
188188

189189
@Override
190-
public Post getCustomPost(Long id, String postTypeName) throws PostNotFoundException {
191-
return getPost(id, postTypeName, Contexts.VIEW);
190+
public Post getCustomPost(Long id, String requestPath) throws PostNotFoundException {
191+
return getPost(id, requestPath, Contexts.VIEW);
192192
}
193193

194194
@Override
@@ -348,14 +348,14 @@ public PostMeta getPostMeta(Long postId, Long metaId) {
348348
}
349349

350350
@Override
351-
public List<PostMeta> getCustomPostMetas(Long postId, String customPostType) {
352-
final ResponseEntity<PostMeta[]> exchange = doExchange1(Request.CUSTOM_POST_METAS, HttpMethod.GET, PostMeta[].class, forExpand(customPostType, postId), null, null);
351+
public List<PostMeta> getCustomPostMetas(Long postId, String requestPath) {
352+
final ResponseEntity<PostMeta[]> exchange = doExchange1(Request.CUSTOM_POST_METAS, HttpMethod.GET, PostMeta[].class, forExpand(requestPath, postId), null, null);
353353
return Arrays.asList(exchange.getBody());
354354
}
355355

356356
@Override
357-
public PostMeta getCustomPostMeta(Long postId, Long metaId, String customPostType) {
358-
final ResponseEntity<PostMeta> exchange = doExchange1(Request.CUSTOM_POST_META, HttpMethod.GET, PostMeta.class, forExpand(customPostType, postId, metaId), null, null);
357+
public PostMeta getCustomPostMeta(Long postId, Long metaId, String requestPath) {
358+
final ResponseEntity<PostMeta> exchange = doExchange1(Request.CUSTOM_POST_META, HttpMethod.GET, PostMeta.class, forExpand(requestPath, postId, metaId), null, null);
359359
return exchange.getBody();
360360
}
361361

@@ -366,12 +366,17 @@ public PostMeta updatePostMetaValue(Long postId, Long metaId, String value) {
366366

367367
@Override
368368
public PostMeta updatePostMeta(Long postId, Long metaId, String key, String value) {
369+
return updatePostMeta(postId, metaId, null, value, Request.META);
370+
}
371+
372+
@Override
373+
public PostMeta updatePostMeta(Long postId, Long metaId, String key, String value, String requestPath) {
369374
ImmutableMap.Builder<String, Object> builder = new ImmutableMap.Builder<>();
370375
BiConsumer<String, Object> biConsumer = (key1, value1) -> ofNullable(value1).ifPresent(v -> builder.put(key1, v));
371376

372377
biConsumer.accept(META_KEY, key);
373378
biConsumer.accept(META_VALUE, value);
374-
final ResponseEntity<PostMeta> exchange = doExchange1(Request.META, HttpMethod.POST, PostMeta.class, forExpand(postId, metaId), null, builder.build());
379+
final ResponseEntity<PostMeta> exchange = doExchange1(requestPath, HttpMethod.POST, PostMeta.class, forExpand(postId, metaId), null, builder.build());
375380

376381
return exchange.getBody();
377382
}

src/main/java/com/afrozaar/wordpress/wpapi/v2/api/PostMetas.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,16 @@ public interface PostMetas {
1515

1616
PostMeta getPostMeta(Long postId, Long metaId);
1717

18-
List<PostMeta> getCustomPostMetas(Long postId, String customPostType);
18+
List<PostMeta> getCustomPostMetas(Long postId, String requestPath);
1919

20-
PostMeta getCustomPostMeta(Long postId, Long metaId, String customPostType);
20+
PostMeta getCustomPostMeta(Long postId, Long metaId, String requestPath);
2121

2222
PostMeta updatePostMetaValue(Long postId, Long metaId, String value);
2323

2424
PostMeta updatePostMeta(Long postId, Long metaId, String key, String value);
2525

26+
PostMeta updatePostMeta(Long postId, Long metaId, String key, String value, String requestPath);
27+
2628
boolean deletePostMeta(Long postId, Long metaId);
2729

2830
boolean deletePostMeta(Long postId, Long metaId, Boolean force);

0 commit comments

Comments
 (0)