This seems like a serious reach but it's something that would help me loads, so currently I have this structure to return the related posts for my music website, and it works flawlessly for returning the results for one website.

$tags = wp_get_post_tags($post->ID);
if ($tags) {
$first_tag = $tags[0]->term_id;
  'post_type' => 'post',
  's' => $loopartist,
  'post__not_in' => array($post->ID),
$my_query = new WP_Query($args);
if( $my_query->have_posts() ) {
while ($my_query->have_posts()) : $my_query->the_post();

Then some content to display blocks would be returned here, and followed by a standard closing with.

} wp_reset_query();

Now like I said, the above works for my singular website.. but how could I make it so that I could also collect the posts for a website on the same server, with the same design, and the same IP address return related posts as well?

1 Answer 1


The easiest way to pull data from another site is by using the Rest API. The interface is not as powerful as WP_Query in terms of the arguments you can pass to the query, but you can still do something like this:

$json = file_get_contents('http://example.com/wp/v2/wp-json/posts?tags=11&per_page=5');
$posts = json_decode($json);

The $posts variable now contains maximum five post objects with from tag with ID 11, which you can loop through in the normal way (assuming you are using WP 4.7 or higher).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.