按元值查询帖子并按另一个元键排序

时间:2016-10-22 作者:user97811

我想查询和排序的元键“流行”的职位,这些职位还必须有另一个元键“去”与值“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\',
    ),
    \'be_price\'    => array(
        \'key\'     => \'gone\',
        \'value\'    => \'1\'
    )
)                     
); 

2 个回复
SO网友:Jeroen Schmit

我不确定是什么\'be_price\' 是的,但我认为$args 应如下所示:

$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\'
    )                     
);

SO网友:Oscprofessionals
$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

相关推荐

将wp_Query替换为wp_User_Query

我在插件中制作了一些订阅者档案和单曲(个人资料页),其中我还包括了一个“用户单曲”模板,通过template_include. 不过,我正在尝试从插件中删除一些模板,以使其使用主题模板。我用了locate_template( \'single.php\' ) 从活动主题中选择单个模板。我没有使用全局wp_query 在本例中显示我的内容,但页面显示了基于查询默认值的循环(十篇帖子)。我想知道的是,我是否可以完全放弃默认查询,用wp_user_query 我可以将查询到的用户ID输入其中。然后我想筛选the