Order by menu structure

You may be able to use a WP_Query on nav_menu_item since it is its own post type. I’ve never done this but maybe it would work like you need it to, worth a shot. There are three other possibilities: Option 1 – Get Your Nav Menu Items There’s a functions called wp_get_nav_menu_items() which will return … Read more

Order By Multiple Meta Fields

One problem with the query is that the self-join with the ambiguous WHERE gives you a crossed dataset (which is masked by the DISTINCT), so it would be simpler to use wp_post as a base to attach the joins that precisely match the keys, eg SELECT p.ID, key1.meta_value as prog_ongoing, key2.meta_value as prog_date_start FROM $wpdb->posts … Read more

order by multiple meta keys in pre_get_posts

Maybe a bit late … add_action( ‘pre_get_posts’, function($query) { if ( !is_admin() && $query->is_main_query() && is_post_type_archive( ‘[your_post_type]’ ) ) { $query->set(‘meta_query’, array( ‘_property_price’ => array( ‘key’ => ‘_property_price’, ), ‘_property_featured’ => array( ‘key’ => ‘_property_featured’, ) )); $query->set(‘orderby’,array( ‘_property_price’ => ‘DESC’, ‘_property_featured’ => ‘DESC’ )); } return $query; } );