admin管理员组文章数量:1122846
Well after hours and hours I find myself finally here, I am building a gutenberg block that is getting a custom post type data and making little cards with it, it works very well if I want to get: All the CPT posts All posts sharing an unique ID
But if I want to filter them using another acf that holds a boolean for my life it does not work, I'll show an example that may easily give you an inside in the problem (pay attention to the is_partner field as it is the one giving me problems):
If I code it like this it works PERFECTLY:
$posts_per_page = 24;
$query_args = array(
'post_type' => 'references',
'posts_per_page' => $posts_per_page,
'post_status' => 'publish',
'paged' => 1,
'meta_key' => 'is_partner',
'meta_value' => '1',
);
if ($categoryID && $categoryID !== 1000 && $categoryID !== 2000) {
$query_args['tax_query'] = array(
array(
'taxonomy' => 'reference-category',
'field' => 'term_id',
'terms' => $categoryID,
),
);
$query = new WP_Query($query_args);
but if I write it like this it does not give me anything:
// Query for the latest custom post type 'references'
$posts_per_page = 24;
$query_args = array(
'post_type' => 'references',
'posts_per_page' => $posts_per_page,
'post_status' => 'publish',
'paged' => 1,
);
if ($categoryID && $categoryID !== 1000 && $categoryID !== 2000) {
$query_args['tax_query'] = array(
array(
'taxonomy' => 'reference-category',
'field' => 'term_id',
'terms' => $categoryID,
),
);
} elseif ($categoryID === 1000) {
$query_args['meta_key'] = 'is_partner';
$query_args['meta_value'] = '1';
} elseif ($categoryID === 2000) {
$query_args['meta_key'] = 'is_partner';
$query_args['meta_value'] = '0';
}
$query = new WP_Query($query_args);
Does anybody can guess why ? I'm losing my mind.
本文标签: wp queryProblem making a WPQuery with ACF boolean
版权声明:本文标题:wp query - Problem making a WPQuery with ACF boolean 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736296749a1929865.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论