admin管理员组

文章数量:1388146

I would like to query and sort posts by meta key "popularity" and these posts must have also another meta key "gone" with value "1" to query

$args = array(
        'post_status' => 'publish',
        'posts_per_page' => '150',
        'cat' => $cat_id, 
        'order' => 'DESC'
'meta_query'      => array(
    'relation'    => 'AND',
    'popularity' => array(
        'key'     => 'popularity',
        'orderby' => 'meta_value_num',
    ),
    'be_price'    => array(
        'key'     => 'gone',
        'value'    => '1'
    )
)                     
); 

I would like to query and sort posts by meta key "popularity" and these posts must have also another meta key "gone" with value "1" to query

$args = array(
        'post_status' => 'publish',
        'posts_per_page' => '150',
        'cat' => $cat_id, 
        'order' => 'DESC'
'meta_query'      => array(
    'relation'    => 'AND',
    'popularity' => array(
        'key'     => 'popularity',
        'orderby' => 'meta_value_num',
    ),
    'be_price'    => array(
        'key'     => 'gone',
        'value'    => '1'
    )
)                     
); 
Share Improve this question asked Oct 22, 2016 at 13:21 user97811user97811 1
Add a comment  | 

2 Answers 2

Reset to default -1

I am not sure what 'be_price' is for, but I think your $args should look like this:

$args = array(
    'post_status' => 'publish',
    'posts_per_page' => '150',
    'cat' => $cat_id, 
    'meta_key' => 'popularity',        
    'order' => 'DESC',
    'orderby' => 'meta_value_num',
    'meta_query' => array(
        'key'     => 'gone',
        'value'    => '1'
    )                     
);
$args = array(
'post_status' => 'publish',
'posts_per_page' => '150',
'cat' => $cat_id,
'order' => 'DESC',
'meta_query'      => array(
'relation'    => 'AND',
'popularity' => array(
    'key'     => 'popularity',
    'orderby' => 'meta_value_num'
),
'gone' => array(
    'key'     => 'gone',
    'value'    => '1'
)
));

try this

本文标签: Query posts by meta value and sort by another meta key