Support

Account

Home Forums Backend Issues (wp-admin) How can I filter the taxonomy field to show only 2nd level terms? Reply To: How can I filter the taxonomy field to show only 2nd level terms?

  • Thanks John,it worked like a charm – I’ve created a multi-select field called “acf-user-schools” and added this:

    function acf_load_user_school_field_choices( $field ) {
    	
        // reset choices
        $field['choices'] = array();
        
    	
                   // Get all the schools hierarchy ( Country -> District -> School )
    	$schools  = getTaxonomyHierarchy( SCHOOLS_TAXONOMY );
    	
    	// Get the children (all the districits) of USA
    	$schools  = $schools [ USA ]->children;
    	
    	if ( !empty( $schools  ) AND !is_wp_error( $schools  ) ) 
    	{
    		foreach( $schools as $district ) 
    		{  
    			$field['choices'][ $district->term_id ] = $district->name;
    		}
    	}
    
        return $field;
        
    }
    add_filter('acf/load_field/name=acf-user-schools', 'acf_load_user_school_field_choices');