Support

Account

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