Home › Forums › Feature Requests › Show field when taxonomy type is enabled › Reply To: Show field when taxonomy type is enabled
Thanks for pointing me in the right direction. Very simple solution.
Having suggestion to enhance this peace of code fork the Gist.
add_filter('acf/location/rule_types', 'acf_location_rules_types');
function acf_location_rules_types( $choices ) {
$choices['Post']['post-type-has-taxonomy'] = __('Post Type has Taxonomy');
return $choices;
}
add_filter( 'acf/location/rule_values/post-type-has-taxonomy', 'acf_location_rules_values_has_taxonomy' );
function acf_location_rules_values_has_taxonomy( $choices ) {
return array_merge($choices, get_taxonomies());
}
add_filter('acf/location/rule_match/post-type-has-taxonomy', 'acf_location_rules_match_has_taxonomy', 10, 3);
function acf_location_rules_match_has_taxonomy( $match, $rule, $options )
{
if ($rule['operator'] == '==') {
$match = is_object_in_taxonomy($options['post_type'], $rule['value']);
} elseif ($rule['operator'] == '!=') {
$match = !is_object_in_taxonomy($options['post_type'], $rule['value']);
}
return $match;
}
edit: add link to Gist
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.