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');
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We’re reaching out to our multilingual users to ask for help in translating ACF 6.1. Help make sure the latest features are available in your language here: https://t.co/TkEc2Exd6U
— Advanced Custom Fields (@wp_acf) May 22, 2023
© 2023 Advanced Custom Fields.
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.