You can create groups of meta_queries using specific compare operation on them, and since you want to order based in a single custom field, you can keep the order declaration dedicated to the single meta … Hello! You can order by that meta value, but I don't think there's a built in way to order by 2 meta values. Check out the new WordPress Code Reference! I might be wrong, but using another filter for that specific purpose … Players has relevant meta fields: First name, last name, and team. How can I order the query using multiple orderby values? I'm using two different custom post types, players and teams. I'm developing a wordpress plugin. I have been working on a plugin to add custom columns to users table and then make them sortable by meta_value and meta_key. For whatever reason, using 'meta_value' => '' and 'meta_compare' => '!=' or 'meta_compare' => 'NOT LIKE' still pulled all posts for me, but it probably has something to do with the fact that I created my meta value using the Advanced Custom Fields (ACF) plugin. If we want to sort by a meta value, or by some other way WordPress doesn't automatically understand you have to tell it what you mean by ordering by 'slice'. WOOCOMMERCE ORDERS IN VERSION 3.0+ Since Woocommerce mega major Update 3.0+ things have changed quite a lot: For WC_Order Object, properties can't be accessed directly anymore as before and will throw some errors. Read more about custom field parameters in the codex. The exception to this rule, as in this example, is the 'meta_value' and 'meta_value_num' parameters, which require us to set a meta key as well. I'm trying to query a custom post type, and within that post type, query a meta value. Class Reference/WP Query Languages : English • Italiano • 한국어 • 日本語 中文(简体) • Português do Brasil • ( Add your language ) ; New WC_Order and WC_Abstract_Order getter and setter methods are now required on the WC_Order object instance. You can order by a second field (here, title), just not a second meta value field (as far as I know). In 'search.php', i want my WP_Query entry/post) list ordered by two of my custom fields and one of wp default parameter:, orderby (word_count title word_type)," -First, order my entries by word_count. WP 4.2 will address this shortcoming with a new syntax for ordering by specific clauses of a ‘meta_query’ array. Internally, ‘meta_key’ and ‘meta_value’ are converted to the first clause in a ‘meta_query’, but this conversion is opaque as far as ‘orderby’ is concerned. That's very clever @LoicTheAztec! Generate the ORDER BY clause for an ‘orderby’ param that is potentially related to a meta query.
; Teams has relevant meta fields of team name. I've been taking Treehouse Wordpress lessons for a while and now working on a bilingual dictionary (spanish-turkish) plugin and a template for it. I have just one doubt: is it as future-proof as using woocommerce_checkout_update_order_meta? Then, I'd like to first sort by menu_order ascending, then by a custom meta value wcu_lastname ascending. ; Also, there are some New classes for Order items: So far I got everything working except the last bit, to make them sort based on the meta_value of a chosen meta_key. ; While editing a specific team post, I'm trying to have an array of all the players that currently have that team's name posted to their meta field for team name. It seems like woocommerce_checkout_update_order_meta was placed there by WooCommerce devs for the specific purpose of updating order meta. However, the orderby value didn't seem to be able to take an array. SELECT wp_posts.ID FROM wp_posts LEFT JOIN wp_postmeta ON (wp_posts.ID = wp_postmeta.post_id AND wp_postmeta.meta_key) ORDER BY wp_postmeta.meta_value DESC, wp_posts.ID ASC; This does return all posts, and 2 and 3 will be correctly ordered by meta_value.