Support

Account

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!