How to do sorting on matapalo in wordpress?

There is such a request:
$popular = new WP_Query( array(
 'post_type' => 'audio',
 'order' => 'ASC',
 'posts_per_page' => -1,
 'meta_query' => array(
array(
 'key' => 'pop',
 'value' => $POP,
)
),
 ));

In the posts there is another metabole - views - number of views.
Question: how to do sorting on matapalo views, if the query it is not present?
April 4th 20 at 13:18
1 answer
April 4th 20 at 13:20
Solution
Try this:
$popular = new WP_Query( array(
 'post_type' => 'audio',
 'order' => 'ASC',
 'meta_key' => 'views',
 'orderby' => 'meta_value_num',
 'posts_per_page' => -1,
 'meta_query' => array(
array(
 'key' => 'pop',
 'value' => $POP,
)
),
 ));
Helped, thank you! Just another question, if the fields to sort a few %) - freeman.Predovic64 commented on April 4th 20 at 13:23
@freeman.Predovic64, https://wp-kama.ru/function/wp_query#orderby
Search in the page "#8 Sort by multiple metaboly". - Kennedy_Quigley commented on April 4th 20 at 13:26
@Kennedy_Quigley, there is one moment, the field must be present in a meta_query, and in my case this is not necessary, since filtering is not performed - freeman.Predovic64 commented on April 4th 20 at 13:29

Find more questions by tags WordPress