我使用简单字段插件添加了一个字段(高级帖子),现在我需要更改流行的帖子小部件。我需要得到所有流行的职位排除溢价职位。
到目前为止我所做的,
原始查询,
$popularposts = new WP_Query(\'showposts=5&meta_key=post_views_count&orderby=meta_value_num&order=DESC&ignore_sticky_posts=1\')
已编辑的查询,
$args1 = array(
\'showposts\' => 5,
\'ignore_sticky_posts\' => 1,
\'meta_query\' => array(
array( \'key\' => \'post_views_count\', \'orderby\' => \'meta_value_num\', \'order\' => DESC ),
array( \'key\' => \'_simple_fields_fieldGroupID_2_fieldID_1_numInSet_0\', \'compare\' =>\'NOT EXISTS\' ),
),
);
$popularposts = new WP_Query($args1);
但它不能提供预期的结果,它排除了高级职位(字段:
_simple_fields_fieldGroupID_2_fieldID_1_numInSet_0
) 但它不是按
post_view_counts
.
任何帮助都将不胜感激。。
最合适的回答,由SO网友:cybmeta 整理而成
正确的查询是:
$args1 = array(
\'showposts\' => 5,
\'ignore_sticky_posts\' => 1,
//ORDER ARGUMENTS
\'meta_key\' => \'post_views_count\',
\'orderby\' => \'meta_key_num\',
\'order\' => \'DESC\',
//META QUERY
\'meta_query\' => array(
array(
\'key\' => \'_simple_fields_fieldGroupID_2_fieldID_1_numInSet_0\',
\'compare\' =>\'NOT EXISTS\' ),
),
);
$popularposts = new WP_Query($args1);
订单总是在外面
meta_query
, 请参见
codex.