How to use ACF True/False to filter categories? [closed]
I’ve looked all over the ACF forums, read the documentation and also looked at similar questions here without success. So, i’m posting with the hopes of figuring out what I’m doing wrong.
I have a True/False ACF field, mba_exclude, attached to my categories. My goal is to simply have a category not show on the front end when the user turns the field to ‘Yes’, which should exclude that category from showing. I plan to have the majority of the categories shown be by default, which is why I have a true statement there in case the user wants to turn it off.
Here’s how I’m querying the categories:
$args = array( 'taxonomy' => 'category', 'hide_empty' => 0, 'meta_query' => [ 'key' => 'mba_exclude', 'value' => '1', ], ); $c = get_categories($args);
Here’s my html for how I’m showing these on the front-end:
foreach ($c as $category): $counter++; ?> <div class="col-12 col-md-4 col-xl-3"> <div class="customize-card-sm checkbox"> <input class="customize-select" id="category-<?php echo $counter ?>" type="checkbox" name="categories" value="<?php echo $category->term_id ?>"> <label for="category-<?php echo $counter ?>"><?php echo $category->name ?></label> </div> </div> <?php endforeach;?>
When I do a var_dump on $c, I get every category still, no matter what. I’ve tried changing the formatting of the meta_query in my code to match the array() style in the ACF docs (above) without success. I’m still newer to WP development, and would appreciate any assistance here. Thanks!