php - Order posts by highest rated in Wordpress -


i'm creating site overviews of posts should possibly ordered rating. rating set in way people can comment on post , submit rating comment of want. want create filter gets posts , shows highest rated posts first.

the way comments single post:

get_comments( array('post_id' => $post->id) ); 

the way rating post:

get_comment_meta($comment->comment_id, 'cijfer', true ); 

now keep in mind not every comment have actual rating attached it. how can modify bit of code gets posts order them rating high -> low.

$order = array (     'order'     => 'asc',     'cat'       => $cat,     'post_type'=> 'adressen',     'paged'     => $paged, ); 

from docs https://codex.wordpress.org/class_reference/wp_query#order_.26_orderby_parameters

'orderby' 'meta_value' , custom post type

display posts of type 'my_custom_post_type', ordered 'age', , filtered show ages 3 , 4 (using meta_query).

$args = array(     'post_type'  => 'my_custom_post_type',     'meta_key'   => 'age',     'orderby'    => 'meta_value_num',     'order'      => 'asc',     'meta_query' => array(         array(             'key'     => 'age',             'value'   => array( 3, 4 ),             'compare' => 'in',         ),     ), ); $query = new wp_query( $args ); 

hope helps


Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -