Forums
Forums / Fixing WordPress / orderby not working in WP_Query
(@itsclarke)
10 years, 4 months ago
I’m working on a multisite using custom post types along with a custom field called listing_index. A user should be able to include a number in this field, allowing manual ordering of these custom post types, but my query appears to be ignoring it.
listing_index
$args = array( 'post_type' => 'kodakalaris_listing', 'posts_per_page' => 4, 'orderby' => array( 'listing_index' => 'DESC', 'meta_value_num' => 'DESC' ), 'meta_query' => array ( array ( 'key' => 'listing_region_slug', 'value' => get_microsite_slug() . '-microsite-home-featured' ), array ( 'key' => 'listing_index' ) ) );
Here’s the site
Those numbers above each listing are their respective listing_index
listing
$args = array( 'post_type' => 'kodakalaris_listing', 'posts_per_page' => 4, 'orderby' => 'index_clause', 'meta_query' => array ( 'site_clause' => array ( 'key' => 'listing_region_slug', 'value' => get_microsite_slug() . '-microsite-home-featured' ), 'index_clause' => array ( 'key' => 'listing_index', ) ) );
Ended up solving my problem. I found the solution here
The topic ‘orderby not working in WP_Query’ is closed to new replies.