• Resolved carlosvai

    (@carlosvai)


    Hi! I could use some help.
    I have a taxonomy field (2 actually, one for category and one for post tag), and I want to exclude certain terms from the checkbox selector.

    I searched all around the internet and found a few snippets to achieve this. For example, this one https://stackoverflow.com/a/58459480/17875280

    But none of them work for me. I tried those snippets, but as a result all the taxonomy terms are displayed in the output selector. Not sure if something has changed in these last years in the ACF core code. Is there a way to achieve this?

    Thanks in advance!

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter carlosvai

    (@carlosvai)

    Update: The code is working fine in the backend with the regular ACF form.

    add_filter('acf/fields/taxonomy/wp_list_categories/name=servicios', 'exclude_taxonomy_args', 10, 2);
    function exclude_taxonomy_args( $args, $field ) {
      $args['exclude'] = array(2053,2145,28); //the IDs of the excluded terms
      return $args;
    }

    I’m using that snippet, and it works fine with the regular ACF form. But when I use it with the frontend form, all tags are visible.

    Thanks.

    Thread Starter carlosvai

    (@carlosvai)

    Update 2:
    The author of the plugin was kind enough to give me the answer, so I will share it over here!

    We simply have to change acf/fields/taxonomy/wp_list_categories for acf/fields/related_terms/wp_list_categories

    The working snippet goes like this

    add_filter('acf/fields/taxonomy/wp_list_categories/name=servicios', 'exclude_taxonomy_args', 10, 2);
    function exclude_taxonomy_args( $args, $field ) {
      $args['exclude'] = array(2053,2145,28); //the IDs of the excluded terms
      return $args;
    }

    “servicios” is the name of my field, of course you should change that accordingly.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Exclude specific taxonomy terms’ is closed to new replies.