Given that meta is cached inside page load it should be reasonably performant to do it like this (not tested):
usort( $wp_query->posts, function ( $post_a, $post_b ) {
$a = get_post_meta( $post_a->id, 'key', true );
$b = get_post_meta( $post_b->id, 'key', true );
if ( $a == $b ) {
return 0;
}
return ( $a < $b ) ? - 1 : 1;
} );
It might be more reasonable to modify query inputs before it’s run though, as per comment.
Related Posts:
- Sort Order for a Custom Query in a Post Type Archive Not Working
- Select All in Parent Category, Group by Child Category?
- WP_Query -> sort results by relevance (= most tags / taxonomy terms in common)
- WP_Query post at custom position
- query order by date on custom type: wrong order
- How to query different post types in specific order?
- Combining sorted and random CPT
- Previous/Next Link by Meta Value in CPT
- Wp_query: sort by PHP variable
- How to do WP_Query with two meta fields with orderby clause
- Order Custom Post Type by Custom Field Value
- Change sort order when using ‘orderby’ => ‘type’
- Having Issue on Ordering CPT by Custom Field In Custom WP Query
- WP_Query of custom post type sorted by meta_key has unexpected results
- WP_Query not resetting after wp_reset_postdata
- Post ordering not working with custom field
- Displaying Portfolio Filter by Category Order (alphabetically)
- Display Parent-Child Posts in specific order by comparing IDs in array
- How can I sort the results of a REST API response by the title of a connected custom post type?
- Order posts alphabetically with numbers but some of the posts has numbers in the title
- SEARCH QUERIES – REVERSE OUTPUT
- Wp Query sort order from custom MetaBox
- WP Query with multiple post types ordered by custom meta date then published date
- Orderby modified only for specific post types
- Custom post order when using OR relation
- 404 on Pages for Custom Post Type & Query_Posts
- WP_query orderby not working after WP4.0 update [closed]
- Query order by meta value force specific tag first
- Order Wp Query by earliest of 3 dates meta query
- Display all posts in a custom post type, grouped by a custom taxonomy
- Query by post title
- Order by & include array by specific post ids
- WP_Query() show posts that end later than today
- How to check if a WP_Query has data
- Sorting a query by custom field date
- Number of pages – multiple (custom) post types
- Retrieving 3 latest post from each of 5 different custom post types
- Get latest 4 post on a custom post filtered by category
- How to sort CPT by custom meta value (date), and return posts month by month
- Wp-query causing problems with the_content();
- wp_query and comment_parent – select only posts with top level comments
- Comparing timestamps in meta query doesn’t work
- Multiple Archive Pages for Custom Post Types AND Taxonomies
- Exclude current post when getting related post on custom post type and taxonomy
- Custom post_type search’s $wp_query->query_vars do not correspond
- wp_query custom post type by taxonomy & standard post by taxonomy
- Query Custom Post Types & category_name?
- Conditional to modify query results
- WP_Query is printing out only one post when posts_per_page is set to multiple
- WP Query to displaying date and posts for that date?
- Use WP_Query() to Output the 4th to 6th Most Recent Posts of a Custom Post Type
- Get all Posts If has same custom field values in Posts
- Custom Post Types not showing, custom WP_Query
- Sorting multiple custom post types without a meta key/value pair by sort order
- Two near-identical custom field types – one works, the other doesn’t . What can cause this?
- Rewrite and custom post type: order by custom field not working
- wp_query check if integer exists in custom field’s array
- Custom-Posttype & Custom Taxonomy WP_Query
- orderby rand is not working for a custom post types
- Stuck in Order by more then one
- Display featured image from one CPT within another CPT query
- WordPress loop: Show only a Custom Post Type Taxononmy TERM
- Why is my category template ignoring post type?
- Retrieve custom post types by custom taxonomies with WP_Query
- Add ‘last’ class to second post in featured post loop
- Ascending Order is not Working in Custom Post Type Listining
- WP_Query Custom Post Type if Category ID Equals
- Trouble with pagination
- Select2 AJAX and WP Query Returns ALL and does not filter
- Custom Category Walker with Image, Fallback to Most Recent Post in Category Image
- List categories, subcategories and posts from custom taxonomy and custom post type
- How to query Posts from a custom post type which contains a custom taxonomy?
- How to retrive Custom Post Type Meta Fields in Custom WP_Query
- filter the_content, custom post type, and wp_query
- Loop for custom-post-type comparing taxonomy terms for “related” posts?
- Get_the_term_list inexplicably adds values in foreach
- Single parent post lists child posts with pagination
- wp_query can’t get max_num_pages in custom post type
- Custom Form / Search with Custom Post Type Data
- Get next and prev item from custom WP_Query and Custom Post Type
- Query to show post current day
- Using ACF values in nested WP queries for CPT with date values in the past
- Pagination Not Working When Used With WP_Query() `offset` Property
- how to display posts content on the custom css popup by clicking on each title on the sidebar?
- How do I insert a custom post type query after a certain number of recent posts and then resume recent posts?
- WP_Query for custom taxonomies showing posts from non-specified terms?
- how to display new private message to users?
- Make pagination work as a carousel (custom query)
- WP_Query with all posts in one custom post type and only posts in another custom post type with a specific category
- Search result based on URL
- subtracting the current post form then whole loop, which is generating all CPT titles
- Displaying WordPress posts from post and custom post type in custom taxonomy
- Loop carousel slider in wordpress
- Manually build WP_Query
- Loop with Custom Post Type and Taxonomies
- New WP_Query not isolating custom post types on front-page template
- Pagination not working on homepage
- How to query custom post then display sections by meta value
- Order custom post type is beign ignored
- WP Query + custom fields: How to query event posts from the current date backwards 6 months and organize it month by month?