Support

Account

Home Forums Front-end Issues Disable certain taxonomy terms

Solving

Disable certain taxonomy terms

  • Hi, I have a taxonomy field that I’d like to customize. I’m displaying the taxonomy as checkboxes. Is there any way to disable some of those checkboxes to prevent user from “unselecting” those terms?
    I know I can remove those unwanted terms via acf/fields/taxonomy/wp_list_categories filter, but that doesn’t work for me. When I remove those terms via the filter, they won’t appear in the form anymore and therefore their connection to the post will be deleted upon save.

    Many thanks for help.

  • The only way that I can think to do this would be to create an acf/update_value filter https://www.advancedcustomfields.com/resources/acf-update_value/ for this field and then add any required term IDs to the value

    
    add_filter('acf/update_value/name=your-field_name', 'force_required_terms', 20, 3);
    function force_required_terms($value, $post_id, $field) {
      // required term ID 1234
      if (!in_array(1234, $value)) {
        $value[] = 1234;
      }
      return $value;
    }
    
  • Thanks for the tip. This may be viable. The problem is that the list of required term IDs is dynamic. Basically User A has access to Term ID 1, 2 and 3 and User B has access to Term ID 2, 3 and 4.
    I can filter the taxonomy for user A that will show him IDs 1, 2, 3 and NOT 4. But as soon as I do this and User B select Term ID 4 and afterwards User A select Term ID 1, the reference to term ID 4 will disappear. I would probably need to first check which Term IDs are already associated with the field then remove all ids that user has access to and merge submitted data with trimmed data using acf-update_value filter as suggested. This seems bit overkill but I’ll probably have to go this route:)

Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic.

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 Cookie Policy. If you continue to use this site, you consent to our use of cookies.