[Answered by Roberthue - I was sorting by meta_value instead of meta_value_num]
I've created a WP_Query that does the following:
- Grabs a list of businesses for sale
- Orders them by a meta query, taken from the URL using get_query_var
- Uses a sort order from the query var
- Checks a meta_query to ensure the sale item is active
For the most part, it works. The meta query properly distinguishes between active and inactive posts, the sort will ascend and descend, there's just one problem... the data sorts like this in descending order:
- 99999
- 749000
- 350000
- 300000
- 2700000
- 249000
- 247000
- 2000000
- 1536000
- 145000
Welp, that's not right...
Here's my query args:
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$listing_args = array(
'post_status' => 'publish',
'post_type' => 'business',
'posts_per_page' => '12',
'meta_key' => get_query_var('orderby'),
'orderby' => 'meta_value',
'order' => get_query_var('order'),
'paged' => $paged,
'meta_query' => array( // Only grab active listings
array(
'key' => 'property_active',
'value' => 1,
'compare' => '='
),
),
);
// The Query
$businesses = new WP_Query( $listing_args );
Far as I can tell, that's not wrong either. The fields themselves are generated by ACF and delegated "numeric".
I'm at a complete loss for ideas.
meta_value_num
instead ofmeta_value
. codex.wordpress.org/Class_Reference/…