This document discusses using the WordPress REST API for building JavaScript applications and liveblogging. It introduces WordPress.js and wpapi libraries that allow accessing WordPress content and making CRUD operations via the REST API from JavaScript. It also describes Wired, an Express-based app that was used to build a liveblogging app for Wired.com that supported over 10,000 concurrent viewers. Finally, it discusses Livebot, a Node.js app that acts as middleware between Slack and the WordPress REST API to manage liveblog posts.
1 of 48
Download to read offline
More Related Content
What the WordPress REST API Means for Javascript Developers
37. // Let's loop through each one, and add the response to post
meta.
// As we get posts, also push those to the main $posts array.
// Reversing this so that we have some better logic for
updating posts.
// Ideally, you don't need to loop through every page, you
could just
// update the most recent page or two.
for ( $i = 0; $i < $times; $i++ ) {
// Fetch a batch of posts
$response = $this->fetch_and_parse( $url, $i );
$more_posts = $response['response']['posts'];
$more_posts = $this->clean_tumblr_response( $more_posts );
if ( ! empty( $more_posts ) ) {
update_post_meta( $post_id, 'liveblog_posts_page_' . $i,
$more_posts );
}
// Add each of the posts to the main post array.
foreach ( $more_posts as $post ) {
$posts[] = $post;
}
}