wordpress - Sort posts by custom field number -
i'm using query posts.
$args = array( 'post_type' => 'spaces', 'post_per_page' => '500', 'orderby' => 'rand', 'meta_key' => 'space-city', 'meta_value' => $search, ); $query = new wp_query($args);
now need order results total of comments on each post. i've custom field number called "space-comments", i've no idea how sort posts second meta_key.
i made tests, able post when "space-comments" has value. when there no value, post don't show up.
any ideia how can start?
the wp_query can accept meta_query argument populated array of sub-arguments. array can have sub arrays each own meta query, can create nice compound searches across meta data.
see example https://codex.wordpress.org/class_reference/wp_query#custom_field_parameters below.
$args = array( 'post_type' => 'product', 'meta_query' => array( array( 'key' => 'color', 'value' => 'blue', 'compare' => 'not like', ), array( 'key' => 'price', 'value' => array( 20, 100 ), 'type' => 'numeric', 'compare' => 'between', ), ), ); $query = new wp_query( $args );
Comments
Post a Comment