You could use the query to filter the content as you intended by using the ‘meta_query’ with filtering options, and for the order part, just add/modify the following parameters:
1. ‘orderby’ => ‘meta_value’
2. ‘meta_key’ => ‘location_level1_value’
3. ‘order’ => ‘ASC’
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | $wp_query = new WP_Query( array ( 'post_type' => 'listing', 'posts_per_page' => '9', 'post_status' => 'publish', 'meta_query' => array( array( 'key' => 'gateway_value', 'value' => 'Yes', 'compare' => '!=' ) ), 'orderby' => 'meta_value', // this means we will be using a selected // meta field to order 'meta_key' => 'location_level1_value', // this states which meta field // will be used in the ordering, // regardless of the filters 'order' => 'ASC', 'paged' => $paged ) ); |
If you like this question & answer and want to contribute, then write your question & answer and email to freewebmentor[@]gmail.com. Your question and answer will appear on FreeWebMentor.com and help other developers.