need to show the recent post from my subdomain to my main domain frontend. I am using below code, but its picking only main domain recent post. any help to fetch subdomain recent post ?
<h2>Recent Posts</h2>
<ul>
<?php
$args = array( 'numberposts' => '5' );
$recent_posts = wp_get_recent_posts( $args );
foreach( $recent_posts as $recent ){
echo '<li><a href="' . get_permalink($recent["ID"]) . '" title="Look '.esc_attr($recent["post_title"]).'" >' . $recent["post_title"].'</a> </li> ';
}
?>
</ul>
EDIT 2:
So it turns out, that you are not running both sites from the same WordPress installation(otherwise referred to as a WordPress Network). Here is what I can suggest that you use in this case.
Put this code in the main site's
functions.php
:Now put this function in your sub-domain's
functions.php
:Then in your main site call this function, where you want your recent posts to appear:
EDIT 1:
Using the sample code that you have in your question, combined with my solution from below, here is what the final code will look like:
Now, you just put that code wherever you had your original code and everything should be working properly.
You need to switch to the blog in question, using the
switch_to_blog($blog_id)
function, where$blog_id
is the ID of the blog(sub-site) in question.Then do your normal get_posts/or equivalent/ function and display/store the posts in the way you want.
Once you're done with that, just call
restore_current_blog()
and that's it.