[API] Begin with REST API – Display others blogs latest posts
https://rudrastyh.com/wordpress/rest-api-get-posts.html
Ví dụ 1:
<?php
// connect to the website endpoint with wp_remote_get() function
// pass params as URL query args, full parameter list is here https://developer.wordpress.org/rest-api/reference/posts/
// at this moment you can use any parameter with Context: View
// it would be strange if you can fetch drafts or private posts, right?
$response = wp_remote_get(add_query_arg(
array(
'per_page' => 2,
), 'http://localhost/wordpress/wp-json/wp/v2/posts')
);
if (!is_wp_error($response) && $response['response']['code'] == 200) {
$remote_posts = json_decode($response['body']); // our posts are here
foreach ($remote_posts as $remote_post) {
// display post titles and excerpts
echo '<div>' . $remote_post->title->rendered . '</div>';
// need more parameters? print_r( $remote_post )
}
}
?>
Ví dụ 2:

Begin with REST API – Display others blogs latest posts
Latest Posts from Matt Mullenweg’s Blog
Posts from Two and More Blogs in Chronological Order
How to Completely Disable REST API /wp-json on your Website

PreviousMột ví dụ sử dụng Transients (ok)NextTạo phân trang, paginate cho Custom WordPress Loop Full (ok)
Last updated
