The orderby
-parameter should be post_date
instead of date.
your code would look something like this:
$blogs = get_last_updated(' ', 0, 1);
foreach ($blogs AS $blog) {
switch_to_blog($blog["blog_id"]);
$args = array(
'orderby' => 'post_date',
'order' => 'DESC',
'numberposts' => 1,
'post_type' => 'post',
'post_status' => 'publish',
'suppress_filters' => true
);
$lastposts = get_posts( $args );
foreach($lastposts as $thispost) {
setup_postdata($thispost);
}
restore_current_blog();
}
Please do not forget to call restore_current_blog()
in your foreach
. If you used switch_to_blog()
more than once before calling restore_current_blog()
, it won’t work anymore.
Related Posts:
- Get posts from Network (Multisite)
- Get Recent Posts by Date in Multisite
- switch_to_blog() performance considerations & alternatives
- Merging multiple wp_query objects
- Use Transient API to cache queries for all posts in all categories?
- WP_Query on different site in a multisite setup
- How to get post from all Blog Multisite to the Main Site?
- Show list of authors with latest post NOT older than a month
- Dynamically Override Fancy Title – Part II
- Get posts from the Main site to sub site – WordPress MultiSites Network
- wp_get_post_terms of cpt but not duplicates if they are used more than once in the loop
- Count total number of post in foreach loop
- only delete post within query / for each statement (front end)
- Database Queries Optimization with new WP_Query
- WordPress multisite – fallback on subsites to main site on 404 and dealing with switch_to_blog function
- Need Help For WPQuery
- Multisite – Global CPT – advices?
- Make a list of sites for each user in WPMU – switch_to_blog (display in SITE_ID: 1)
- Warning: Invalid argument supplied for foreach(). when creating a WP_query
- Multisite wp_query & switch_to_blog issue
- Stuck in the query loop
- the_post() within switch_to_blog() altering my excerpt
- Simplest way to query with blog_id?
- Redirect to another page using contact form 7? [closed]
- Assign custom parameter to each post in query
- How do I turn these values from MYSQL into an array
- How can i show pagenavi in my author.php?
- In a WordPress multisite configuration, how do I instruct WP_Query() to return posts from a sub-site?
- Different query result on local and server
- Transfer WordPress Login Session to an Extended Webpage on the Same Domain
- Problem with infinite scroll on multisite with custom query
- use system script advertising in wordpress multisite
- Custom post type archive organized by category
- WP_Query with “post_title LIKE ‘something%'”?
- How to extend WP_Query to include custom table in query?
- compare meta_query in get_posts arguments
- How do I order pages and categories by ID or name in the same query?
- How to do a query only on a specific admin page?
- WP Cron and wp_insert_post
- How to adjust found_posts so that it accounts for offset and pagination
- SQL query equivalent to WP User Query
- Function to check if author has posted within the last x days
- Show default content if custom WP_Query has no posts
- WP Query for Posts (Products) in Specific Category that has 2 Specific Tags (*AND* both tags not *OR*)
- WP_Query Performance Issues with meta_query
- Advanced WP Query hogs the SQL server
- Display children and grandchildren of a custom post type
- How to use order RAND() on WordPress?
- WP_QUERY loop, offset in the arguments and the paginate_links – can these work together?
- wp_query for displaying attachments with a tag
- Meta box dropdown of custom posts
- Query: offset post list, unless it’s a specific category
- How to query for pages/post depending on slug?
- Sorting events by descending date, and ascending time if multiple events on a date
- WP_Query orderby author__in
- Combining categories (Query posts with multiple taxonomy terms)
- Filtering out child category posts from parent category archive not working
- Custom query, checking values of multiple meta keys
- Custom Query include private posts in pagination count calculations?
- wp_update_post not working
- WP_Query with offset and ‘orderby’ => ‘rand’, offset not working
- WP_Query Limit Data_Query last 90 days
- Sort WordPress Posts Meta value by Week not Day
- Best choice for multiple loop in page?
- Is it best to avoid using $wpdb for security issues?
- wp_query get data from advanced custom field in wordpress
- How to create custom query by keyword in post title?
- Get Child Category only
- Order is breaking wp_query
- Different options per post type in WP_Query
- How to display all posts not in a post_format
- How to filter query loop block with a search string from the query parameters
- WP_Query – How to get all posts of specific days of week by custom field date?
- How can I comment comma-separated array values?
- WP_Query returns no posts for category
- Using Wp_Query, Json to add Highcharts series data
- Post__not_in only removing first 2 pages
- Query posts by searching for a string in a meta field
- Added Date Filter To Popular Posts Query
- How can I build a query that returns all attachments of a page and it’s children pages?
- Query ACF relationship field – Comparator IN – Value array
- Use get_cat_ID to retreive multiple category IDs
- the content of the uploads folder gets deleted periodically, how to figure out what causes it?
- Need to show 7 posts from actual date
- WP_Query paginate with one term per page?
- using custom meta user data to run queries in WordPress
- Meta query not showing result properly
- Look for string in posts and postmeta
- Multiple meta_query not working
- making a search.php query
- List all blogs apart from the current blog and main blog in WordPress Multisite
- Save query in function for custom gallery
- WordPress wp_query add custom query as field
- 3 wp_query on one page with pagination for last query
- Randomly display posts on a site hosted by WPEngine? [closed]
- tax_query not working properly with get_posts
- how to add limit records in wordpress query
- Get access to all terms associated to each post that the wp_query loop displays
- WP_Query by meta key not returning any posts
- Is there another way to retrieve a post_id from post_meta other than a SQL query?