php - Order wp_query by numeric custom field -
i'm trying allow users sort list of results wp_query
numeric custom field value. users can click button alter sort values, when cost selected, wp_query
looks like:
'meta_key' => 'adult', 'orderby' => 'meta_value_num', 'order' => 'asc',
the field numeric field acf (acf 5 beta beingness used) step
size of 0.01
allow prices 9.99.
however, if run query returns no results every time, when there results should matching.
any ideas i'm going wrong?
edit - total query
$keywordstring = $_session['search']['keyword']; $keywords = explode(', ', $keywordstring); $taxquery = array( 'relation' => 'and', array ( 'taxonomy' => 'main-cat', 'field' => 'slug', 'terms' => $_session['search']['cat'] ) ); if( $_session['search']['keyword'] != '' ) { $taxquery[] = array( 'taxonomy' => 'sub-cat', 'field' => 'name', 'terms' => $keywords ); } $args = array( // general 'post__in' => $postids, 'post_type' => 'event', 'posts_per_page' => 10, 'paged' => $paged, 'cache_results' => false, 'meta_key' => $_session['search']['sort-key'], // becomes 'adult' 'orderby' => $_session['search']['sort-by'], // becomes 'meta_value_num' 'order' => 'asc', // category filter 'tax_query' => $taxquery, // date filter meta_query' => array( 'relation' => 'and', array( 'key' => 'date_%_start-date', 'value' => $when, 'compare' => '>=', 'type' => 'numeric' ), array ( 'key' => 'date_%_end-date', 'value' => $when2, 'compare' => '<=', 'type' => 'numeric' ) ) ); $temp = $wp_query; $wp_query = null; $wp_query = new wp_query( $args );
php sql wordpress acf
No comments:
Post a Comment