Skip to content

Instantly share code, notes, and snippets.

@rieckpil
Created October 3, 2019 18:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rieckpil/e019cf7c05afbbcad964efa897008f0b to your computer and use it in GitHub Desktop.
Save rieckpil/e019cf7c05afbbcad964efa897008f0b to your computer and use it in GitHub Desktop.
WP API get all posts
@ApplicationScoped
public class WpClient {
public void getListOfBlogPosts(@Observes @Initialized(ApplicationScoped.class) Object object) {
Client client = ClientBuilder.newBuilder().build();
WebTarget webTarget = client.target("https://rieckpil.de/wp-json/wp/v2/posts");
JsonArray result = webTarget
.queryParam("per_page", 100)
.request()
.accept(MediaType.APPLICATION_JSON)
.get(JsonArray.class);
List<String> allBlogPosts = result
.stream()
.filter(jsonValue -> jsonValue.asJsonObject().getString("link").contains("how"))
.map(jsonValue -> jsonValue.asJsonObject().getJsonObject("title").getString("rendered"))
.collect(Collectors.toList());
for (String title :
allBlogPosts) {
System.out.println(title);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment