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
- Adding hreflang tags automatically in WordPress subdirectory multisite
- While creating Block Themes in WordPress, how can I query custom posts for an Archive view?
- How to filter posts by post format “standard” from wp-json api?
- Why is variable not working on custom sql query using wpdb?
- How To Fix WP Query Returns Results But Shouldn’t?
- Order by slug in get_terms with multiple taxonomies
- Get posts for which a custom field is not present, with get_posts
- Output an array of terms for a ‘tax_query’ => array()
- Query with a meta value inside a given range
- How to do multiple searches (with logical OR) in WP_Query in hook pre_get_posts?
- Pagination of a WP_Query Loop in a child-page page template
- How to choose between hooking into per_get_posts or into parse_query
- How to use WP_Query without breaking the main Query
- Add condition of user capability in WP_query
- WP Pagination on Posts Search Results Page resulting from AJAX WP Query
- How to avoid wp_query returning the same post I’m on in results?
- Meta Query relation “AND” not working
- why update and delete query not worked in custom table?
- get_users is missing or skipping over users in loop
- Woocommerce returns Product post_status as published even tho it is in status draft
- Trouble with wp_reset_postdata() in Admin Panel
- remove query arg from url after set query
- Can’t search posts using WP_QUERY inside AJAX Function
- Creating query to show which editor (classic or block) was last used to edit a post/page
- ACF Date Based wp_query
- Tax query clause inside a meta query clause?
- How to query for pages/post depending on slug?
- How to loop for every result found in the_content() when using the search query?
- get_posts() not working with multiple statuses
- Custom query for sidebar isn’t returning results
- How to vary post loop results layout and resume?
- How can I use wp_query to show all product data using just the products ID?
- Multiple taxonomy And acf filter group by
- if statement in wp_query arguments
- WordPress Related Post by tags in Single.php
- Accessing post’s meta data based on user’s click of a post
- Need wp_query to return all children and grandchildren
- Function get_queried_object() return NULL in custom taxonomy
- How to use offset in WP_Query
- Get number of authors
- exclude posts with a specific custom field and value
- difference between like ‘%%%var%%’ and ‘%var%’
- WP Query Category Atribute Not Working
- Unexpected end of file
- Using Ajax to load more posts | Help me change the wording on my button to notify the user
- Redirect page when URL parameter not set
- WP_Query To call data from diffrent tables
- Get Current User Id Inside a Loop Returns 0 For a Shortcode
- list pages using page.php and NOT page-{slug}.php
- new WP_Query with author argument return no results
- List of the years with posts presented
- How to display upcoming events by dat with Modern Events Calendar Lite
- Changing WP_Query params with url Query Var
- How to combine two or more WP_Query?
- Create A Loop With A Variable Number of Posts For Each Bootstrap Row?
- need to exclude APP_TAX_STORE => $term->slug
- Random order of WP_Query results with highest meta value
- Set Transient does nothing
- Assigning a meta_query value based on regexp to wp_query fails
- Get amount of CPT with a certain custom field value
- Custom page archive query by url var calling page twice on one of my custom queries?
- Getting Taxonomy inside WP_Query Loop
- WordPress custom slug (endpoint) and compare all links
- Meta Query Array Error 500
- Nested tax_query that allows specified categories OR tags, but NOT other categories
- How to use filter hook “the_posts” with a function that refers to $this?
- (Solved) WP_Query ($ args) -> How to sort letters and numbers within the same array