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