Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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