Skip to content

Instantly share code, notes, and snippets.

@bearded-avenger
Created November 7, 2014 19:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bearded-avenger/2124531bd5ead1634301 to your computer and use it in GitHub Desktop.
Save bearded-avenger/2124531bd5ead1634301 to your computer and use it in GitHub Desktop.
Return a list of posts by a specific author no matter the site on the multisite network
/**
*
* Return a list of posts by a specific author no matter the site on the multisite network
*
* @param $userid int id of a user
* @param $limit int number of results to return
*
*
*/
function get_user_posts_on_network( $userid = 0, $limit = 9 ) {
if ( empty( $userid ) )
return;
$blogs = get_blogs_of_user( $userid );
$out = '';
if ( $blogs ):
foreach ( $blogs as $blog ) {
switch_to_blog( $blog->userblog_id );
$posts = get_posts( array('posts_per_page' => $limit, 'author' => $userid ) );
if ( $posts ) :
foreach ($posts as $key => $post) {
setup_postdata( $post );
$out .= $post->post_title;
}
wp_reset_postdata();
endif;
restore_current_blog();
}
endif;
return $out;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment