如何在WP查询中使用两个自定义字段

时间:2016-10-30 作者:sandweb

如何在WP查询中使用两个自定义字段,一个(\'edition\')仅选择一些文章,另一个(\'order\')对文章进行排序。我尝试使用此代码,但排序不起作用。

// args
$args = array(
\'posts_per_page\'    => 6,
\'post_type\'         => \'post\',
\'post_status\'       => \'future\',
\'meta_query\'        => array(
                        array(
                            \'key\' => \'edition\',
                            \'value\' => 1,
                         ),
                        ),
\'meta_value_num\'    => \'order\',
\'orderby\'           => \'meta_value_num\',
\'order\'             => \'ASC\'
);

1 个回复
SO网友:sandweb

I solved with this

$args = array(
\'posts_per_page\'        => 6,
\'post_type\'         => \'post\',
\'post_status\'       => \'future\',
\'meta_key\'          => \'listorder\',
\'order\'             => \'ASC\',
\'orderby\'           =>  \'meta_value_num\',
\'meta_query\'        => array(
                        array(
                            \'key\' => \'edition\',
                            \'value\' => 1,
                         ),
                        ),
);