Home › Forums › ACF PRO › Exclude taxonomy terms from frontend display › Reply To: Exclude taxonomy terms from frontend display
Answering my own question above. This is how you can exclude categories based on slug. In my case, I have a multi-site and category id may change. Following example is to hide the Uncategorized category. (I’d like to keep it as the default one and not rename it for my own reasons). Hope that helps somebody in the same situation.
// get term id's
add_action( 'init', 'get_term_ids' );
function get_term_ids() {
global $uncategorized_id;
$u = get_term_by( 'slug', 'uncategorized', 'product_cat' );
$uncategorized_id = $u->term_id;
}
// exclude categories from category dropdown
add_filter('acf/fields/taxonomy/query/name=category', 'exclude_categories', 10, 2);
function exclude_categories( $args, $field ) {
global $uncategorized_id;
$args['exclude'] = array($uncategorized_id); //the IDs of the excluded terms
return $args;
}
Thanks everyone!
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.