Home › Forums › Feature Requests › Conditional Logic using Taxonomy field › Reply To: Conditional Logic using Taxonomy field
Very long thread so sorry if this has already been suggested… but I was wondering about this too and my first thought was… why not use a Select field instead of a Taxonomy field (where conditional logic is already natively supported) and then use some simple PHP to populate the select field. Like this:
// Programmically Populate an ACF Select Box
function acf_load_type_field_choices( $field ) {
$choices = get_terms( 'battery_type', array('hide_empty' => false) );
if( is_array( $choices ) ) {
foreach( $choices as $choice ) {
$value = $choice->slug;
$label = $choice->name;
$field['choices'][$value] = $label;
}
}
return $field;
}
add_filter('acf/load_field/name=type', 'acf_load_type_field_choices');
This is probably not a great solution though because you have the data in two places not… the taxonomy and the select field. Just a thought. Was hoping to think of a clever solution easier than writing a bunch of JS.
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 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 Privacy Policy. If you continue to use this site, you consent to our use of cookies.