You can use 'posts_orderby'
filter to change the SQL performed.
Note that:
- using
get_posts()
you need to set'suppress_filters'
argument offalse
for the filter to be performed - if you don’t explicitly set
'post_status'
you’ll get only published posts (so no much to order)
Code sample:
$filter = function() {
return 'post_status ASC';
};
add_filter('posts_orderby', $filter);
$posts = get_posts('post_status' => 'any', 'suppress_filters' => false);
remove_filter('posts_orderby', $filter);
Related Posts:
- When to use WP_query(), query_posts() and pre_get_posts
- How to use the_posts_navigation for wp_query and get_posts?
- WP_Query vs get_posts
- meta_query: using BETWEEN with floats and/or casting to DECIMAL
- Get posts from Network (Multisite)
- Using get_posts vs. WP_Query
- Get Recent Posts by Date in Multisite
- get_template_part in for loop
- How-to exclude terms from the main query the most performant way?
- Is it possible to select against a post’s parent’s fields with WP_Query?
- Query all posts where meta value is empty
- Get posts by meta data OR title
- Get_post() with meta_key when compare is a date
- get_posts not finding argument: post_name
- Function to check if author has posted within the last x days
- Use post__in and post__not_in together?
- What should I use, get_posts or wp_query for less CPU load?
- How to get post from all Blog Multisite to the Main Site?
- WP Query post meta value
- Get all posts without tags
- get_posts() seemingly ignoring post_type
- Can not switch the queried post in pre_get_posts hook
- How to find out what “Blog pages show at most” is set to [duplicate]
- Count posts returned by get_posts in external PHP script
- Trying to check and see if a post has a featured image outside of the main loop
- SELECT * FROM $wpdb->posts WHERE ID > 160
- Adding multiple post queries with parent and children to page – Best Way
- Get posts for last working week in WP_Query
- get_posts – get all posts by array of author
- Create a sitemap without a plugin – get parent pages only?
- Creating a custom search for a specific post type
- get_posts – find out if querystring was crap and fallback is used
- Get posts for which a custom field is not present, with get_posts
- Creating query to show which editor (classic or block) was last used to edit a post/page
- get_posts() not working with multiple statuses
- Return only post(s) which have post_excerpt
- Return Taxonomy/Term Information with Posts (WP_Query/get_posts)
- WP_Query() and get_posts() can’t handle over a thousand posts?
- add active class based on permalink and url
- Weird orderby => post__in issue
- Why does get_posts only show results for Admins or logged-out users?
- Conflict with get_posts and the_content
- WP_Query post_parent parameter always returns children of current page
- get_post_meta slowing down my page load (in a plugin)
- How to show more post at a given category?
- Get posts by list of post IDs ordered by those IDs?
- Reset WordPress Post Query to default
- Best choice for multiple loop in page?
- meta_query: check if number exists
- get_posts output always same post
- Use WP_Query or query_posts() or get_posts() for optimizing a site?
- get_posts always returning the same number of posts = 5
- “paged” in WP_Query returns 0 posts
- Specify strict ‘order by’ in WordPress query
- get_posts() and global variables
- How I can change the condition or compare operator for WP_Query in pre_get_posts
- Check if searched number is within the post meta value
- Using get_posts to get posts based on a checkbox value with Advanced Custom Fields
- How to apply a function to a metadata value before launch a WP Query?
- Woocommerce: order posts by meta key
- WP_User_Query and user posts
- How to get posts by category and by choosing a taxonomy term?
- How to access $wp_query object from array of posts given by get_posts?
- Function using get_posts() with tax_query not working when called from functions.php
- Search for pages with permalink
- Execute PHP function inside the admin area
- Why always one post missing
- Magazine style frontpage with multiple categories/loops and no duplicate posts
- Prioritising and Ordering Posts By Category Name Using A Custom Loop
- How to add date_query to meta_query array
- Why my query is not “Main_query”?
- Facing problem with tax_query results
- Populate select list with meta values from all posts of a Custom Post Type
- Form checkbox value going to dynamic URL
- get_posts return only first result
- Related posts queries
- How to get meta key list efficiently?
- how to get wp_query posts only first letter of alphabet A?
- get_posts query caching?
- Get posts with any value in attribute
- Slow query when selecting with large meta query or post__in
- Ordering Posts by parent category, name ascending
- Use not custom fields in get_posts() meta_query?
- Mathematical operations on custom field values? (updated)
- Display posts from catagories
- Both WP_Query and get_posts returning 1 post
- When should you use WP_Query vs query_posts() vs get_posts()?
- get_posts works but new wp_query doesn’t
- Why WP_Query in functions.php is not working when get_posts works?
- Query specific number of posts for each post type in specific order
- get_posts shows current post, not defined posts with args
- Weird query with get_posts and WP_Query
- orderby and order filter in get_posts or WP_query function in wordpress not working
- tax_query not working properly with get_posts
- Query custom post types by meta field in a term from custom taxonomy
- How to retrieve _embed (etc) fields in get_posts custom query?
- WordPress extremely slow when using get_posts with multiple meta_query relations
- Empty query on Custom Post Type, using WP_Query or get_posts
- A Depth Like Parameter For “get_posts”
- Sort by multiple columns using get_posts