The documentation for WP_Query
indicates that ordering by meta value is limited to one meta key and requires the meta_key
parameter (untested):
$results = new WP_Query( array(
'meta_key' => 'wpcf_catalogue_number',
'orderby' => array(
'meta_value_num' => 'ASC',
),
) );
If you want additional sorting, you’ll need to sort the result ($results->posts
) using PHP (untested):
$sort__formats = array();
// Other sorting arrays.
foreach ( $results->posts as $post ) {
$formats[] = get_post_meta( $post->ID, 'format', true );
// Other values added to sorting arrays.
}
array_multisort( $results->posts, $sort__formats, SORT_ASC, ... );
This won’t be highly performant, so you’ll likely want to consider a more performant approach, like combining all the meta values into one, and sorting off of that.
Related Posts:
- Sorting meta_value as integer doesn’t work
- Order (by ASC) posts with meta_key so posts without values are last
- How to only display posts whose meta_value field is not empty?
- Query to sort a list by meta key first (if it exists), and show remaining posts without meta key ordered by title
- Ignoring initial articles (like ‘a’, ‘an’ or ‘the’) when sorting queries?
- Sorting: custom query with orderby meta_value_num THEN by title
- Sort posts by category name and title
- How to get order of posts?
- Is it possible to orderby multiple meta_keys when using meta_value_num?
- How to get Page/Post Gallery attachment images in order they are set in backend using WP_Query()?
- WP Query orderby meta key natural sort?
- WP_Query with meta_value LIKE ‘something%’
- Loop through all tags & output posts in alphabetical list
- Sorting Posts by custom field
- Sort in WP_Query(), not filter? Is it possible?
- Front End Sorting Questions
- Woocommerce custom loop to show all the products [closed]
- Sort by meta key on archive page
- Add a default meta_value to new posts
- How to sort posts in admin by titles with dd.mm.yyyy format?
- Ordering by meta_value AND date NOT WORKING with wp_query
- How to make orderby ‘meta_value_num’ OPTIONAL?
- How to use Meta Value Compare in WP_Query For Max and Min numbers
- Custom WP Query from meta_value stored as serialised array
- Meta query with order by another custom field
- Ordering Posts Type A by Custom Fields of related Post Type B
- How do I sort posts with multiple pages
- WP_Query posts by distance based on LAT & LNG in Database
- Custom query for sidebar isn’t returning results
- Need wp_query to return all children and grandchildren
- Changing WP_Query params with url Query Var
- new WP_Query to get max price meta value not working
- Query multiple meta values
- Why isn’t my `meta_query` array functioning properly?
- How to orderby multiple meta fields if some fields are empty
- Sort wordpress custom posts based on meta value
- WP_Query: Group events by year, sorted DESC; then by date for each year group, sorted ASC
- Meta_query on same meta key, with diffrenct values
- WordPress Comments sort by custom meta key
- Understanding the orderby in WP_Query?
- WP_query sorting can’t sort danish letters (æ, ø, å)
- How to extract specific post
- Help ordering Post loop by two meta values
- Meta Query relation “AND” then set array accordingly
- How to sort a custom wordpress query by combination of meta values?
- Gallery shortcode numerical sorting
- WP Group posts by year(desc) > month(desc) > date(asc)
- Does wp track views for posts?
- Sort WordPress Posts Meta value by Week not Day
- I am having problem sorting custom post type using WP_Query
- Does meta_value (array) work with ‘orderby’?
- WP Query Meta Value – How To Identify Specific, Unique Values?
- Sorting search results with custom dropdown
- Display all posts in a custom post type, grouped by a custom taxonomy. How to sort the posts alphabetically and the terms by ID?
- How do I sort this custom list of sticky posts
- WP Query and date format
- query post by author gender
- Show posts of an advanced search form
- Meta query with compare by more than 2 fields
- How to sort queried pages by an array of page ids?
- orderby ignored by wp_query
- Customize the Sorting Dropdown in WooCommerce use another list or more page
- How to sort store location by specific category order in WP store locations
- Save queried result into database
- how to include orderby value that is empty?
- How to sort wordpress posts already selected by WP_QUERY
- Sort by price wpdb
- Custom Woocommerce Product Query
- How sort products by calculate value? ( custom post meta, price, option)
- WP_Query multiple value not working
- Get authors list and sort them by recent posts
- Move some posts to end of sort order, even if there is a sort in the wp_Query already
- Order by value of Custom Field using url string
- WP Query with meta queries
- Query to sort a list by meta key first (if it exists), and show remaining posts without meta key ordered by title
- Order 2 meta_queries differently in WP_Query?
- Case insensitive ORDERBY in wpquery
- Sort posts on custom field AND after that sort on date?
- How to mix two orderby-parameters into one ordered result
- Sorting Posts by Taxonomy thats not within the query’s $args
- Ignoring ‘a’ when sorting posts
- Display three sequential posts on each page load, without repeating previous
- Order posts by more than one variable (meta_key and publish date AND time)
- Combine WP_Query with array of custom data to single loop without breaking the pagination
- Sorting posts by meta values: 2 different orders
- Sorting Posts with meta value not working
- Sorting is not working in WordPress WP_Query
- Cannot order by in WP_Query
- How to sort a WP_Query array by post_name after an array_merge();
- Query to get all the posts of more than 2 meta_value having same meta_key?
- Sorting: custom query with orderby meta_value_num THEN by title
- query_posts with sorting on a custom datestamp
- Sort Posts with custom meta key by default which is currently set as optional
- Order by meta values
- query_posts, oderby meta_value & print “future” posts
- wordpress sorting using array merge by price in ascending order but price with 0 must be show last
- have_posts order by title descending
- WP_Query – order with usort by custom meta
- Sort by multiple columns using get_posts
- WP Query order posts not working