I am a newbie who needs to produce a chronological list of recent posts from all sites to which a user is subscribed on a WordPress multisite network.
Using the code below, I am able to produce a list where the posts are ordered chronologically (DESC) but grouped by site:
- Site A Wednesday
- Site A Tuesday
- Site A Monday
- Site B Wednesday
- Site B Tuesday
- Site B Monday
I need to produce a list where all posts are ordered chronologically:
- Site A Wednesday
- Site B Wednesday
- Site A Tuesday
- Site B Tuesday
- Site A Monday
Site B Monday
$user = get_current_user_id(); $blogs = get_blogs_of_user( $user ); if( $blogs ) { foreach( $blogs as $blog ) { switch_to_blog( $blog->userblog_id ); $query = new WP_Query ('posts_per_page=2'); if ($query->have_posts()) : while ($query->have_posts()) : $query->the_post(); <li> <a href="<?php echo $string; ?>$ </li> <?php endwhile; $ restore_current_blog(); } } ?>
?>
When I have attempted to apply 'order by' to the WP_Query using (new WP_Query( array( 'order by' => 'date' ), I'm producing the first list above (a list ordered chronologically, grouped by site). I have the feeling that I'm supposed to be sending the output of WP_Query to an array, sorting the array, and then printing this to the page, but as I am extremely new to all of this, I could really use some guidance at this point. Thanks.