我想循环浏览帖子,只显示那些自定义字段_shop
不为空
我总是对元查询感到困惑,甚至不确定是否可以使用它。以下是我迄今为止所做的尝试
$args = array(\'post_type\' => \'jobs\',
\'posts_per_page\' => 12,
\'paged\'=> $paged,
\'tax_query\' => array(
array(
\'taxonomy\' => \'job_category\',
\'field\' => \'slug\',
\'terms\' => $term->slug,
),
),
\'meta_query\' => array(
array(
\'key\' => \'_shop\',
\'value\' => \'\',
\'compare\' => \'!=\'
)
)
\'meta_key\' => \'_shop\',
);
$loop = new WP_Query( $args );
最合适的回答,由SO网友:Milo 整理而成
要选择具有元值的帖子,请使用EXISTS
比较运算符。
$args = array(
\'post_type\' => \'jobs\',
\'posts_per_page\' => 12,
\'paged\'=> $paged,
\'tax_query\' => array(
array(
\'taxonomy\' => \'job_category\',
\'field\' => \'slug\',
\'terms\' => $term->slug,
)
),
\'meta_query\' => array(
array(
\'key\' => \'_shop\',
\'compare\' => \'EXISTS\'
)
)
);