我需要带有两个自定义字段的Wp\\u查询,一个自定义字段用于orderby,另一个自定义字段:(如果帖子中存在此键,请显示帖子,否则不要将此帖子添加到查询中。)我试过了,但没用。。。有什么帮助吗?
$args = array(
\'post_type\' => \'post\',
\'meta_query\' => array(
array(
\'key\' => \'Apple\',
),
array(
\'key\' => \'Price\',
\'type\' => \'numeric\',
)
),
\'orderby\' => \'meta_value_num\',
\'paged\' => get_query_var(\'paged\'),
\'order\'=> \'DESC\',
);
$the_query = new WP_Query( $args );
正如你所看到的,我想显示有自定义字段“Apple”的帖子,并想按自定义字段“Price”从最低到最高的价格进行订购。
SO网友:Bainternet
try this:
$args = array(
\'post_type\' => \'post\',
\'meta_query\' => array(
array(
\'key\' => \'Apple\',
\'value\' => \'\',
\'compare\' => \'NOT LIKE\'
)
),
\'meta_key\' => \'Price\',
\'orderby\' => \'meta_value_num\',
\'paged\' => get_query_var(\'paged\'),
\'order\'=> \'DESC\',
);
$the_query = new WP_Query( $args );