Support

Account

Home Forums Backend Issues (wp-admin) "Create terms" form: pre-select parent field and/or change the new term object Reply To: "Create terms" form: pre-select parent field and/or change the new term object

  • Since you are using the acf/fields/taxonomy/wp_list_categories hook you can limit the terms available in the “parent” field by using the acf/fields/taxonomy/query filter.

    For anyone that is reading this that is using a select field rather than a checkbox or radio field like the OP and using acf/fields/taxonomy/query to limit selections you can do this by using different filters for each. A simple example

    
    funcition my_taxonomy_filter($args, $field, $post_id) {
      // this is the filter for limiting selection is the taxonomy field
    }
    add_filter('acf/fields/taxonomy/query/field_key=field_XXXXXXX', 'my_taxonomy_filter', 10, 3);
    
    function my_secondary_taxonomy_filter($args, $field, $post_id) {
      // this is the secondary filter used when getting values to show in parents
    }
    // this action is fired when then add term popup is loaded
    // what we want to do here is switch the filter to use when adding a term
    // done with a low priority to switch it before ACF does the query
    add_action('wp_ajax_acf/fields/taxonomy/add_term', 0);
    
    function switch_taxonomy_filters() {
      // switch which filter to use when adding terms
      remove_filter('acf/fields/taxonomy/query/field_key=field_XXXXXXX', 'my_taxonomy_filter', 10);
      add_filter('acf/fields/taxonomy/query/field_key=field_XXXXXXX', 'my_secondary_taxonomy_filter', 10, 3);
    }
    

    You should also not that if you are using the acf/fields/taxonomy/query for your field and you don’t want the parent field filtered that you should still remove the main filter because as you can see, it operates on both the field and the parent and your parents will only show what is available in the main field.