arguments - Wordpress - WP_Query Multiple OrderBy Meta_Key -


i want output list of guides, each guide has votes , rating. want sort guide list rating , votes.

example:

guide name      rating    votes guide1            10        3 guide2            10        2 guide3            10        1 guide4            9         6 guide5            9         2 

so have order guides 2 meta_key

omvp_vote_rating , omvp_total_vote 

i have tried many many ways work, haven't got yet. there 1 way have working, problem can't order meta_key, can order normal field comment_count, modified, date, rand (random), title ... here code

$args = array(         'post_type' => 'guides',         'meta_key' => 'omvp_vote_rating',         'post_status' => 'publish',          'posts_per_page' => 20,         'meta_query' => array(             array(                 'key' => 'omvp_vote_rating',                 'compare' => '>=',                 'value' => 0             ),             array(                 'key' => 'omvp_total_vote',                 'compare' => '>=',                 'value' => 0             ),         ),         'orderby'    => array(             'title' => 'asc', //<- working             'omvp_total_vote' => 'desc' //<- not working         ),     ); $wp_query = new wp_query( $args ); 

you can custom select query instead.

$query = "select * $wpdb->posts left join $wpdb->postmeta rating on( $wpdb->posts.id = rating.post_id , rating.meta_key = 'omvp_vote_rating' ) left join $wpdb->postmeta vote on( $wpdb->posts.id = vote.post_id , vote.meta_key = 'omvp_total_vote' ) $wpdb->term_taxonomy.term_id = 3  , $wpdb->posts.post_status = 'publish' order rating.meta_value, vote.meta_value asc limit 0,20"  $posts = $wpdb->get_results($query, object); 

Comments

Popular posts from this blog

sql - VB.NET Operand type clash: date is incompatible with int error -

SVG stroke-linecap doesn't work for circles in Firefox? -

python - TypeError: Scalar value for argument 'color' is not numeric in openCV -