No ACF fields available for taxonomy, if custom location rule is set
Hey,
i use a custom acf location rule to display a field group only for top level categories.
When the location rule is applied/saved, no ACF fields show up in the admin columns config screen for the category.
The rule says: “Show field if this a a category taxonomy AND if this is a top level category”.
Is there a way to make this work?
plugin code:
defined('ABSPATH') or die();
add_filter('acf/location/rule_types', 'acf_location_rules_types');
function acf_location_rules_types( $choices ) {
//error_log(var_export($choices, 1), 0);
$choices['Other']['taxonomy_hierarchy'] = 'Taxonomie-Hierarchie';
return $choices;
}
add_filter('acf/location/rule_values/taxonomy_hierarchy', 'acf_location_rules_values_tax_hierarchy');
function acf_location_rules_values_tax_hierarchy( $choices ) {
$choices[ 'parent' ] = 'Übergeordnete Taxonomie';
$choices[ 'child' ] = 'Untergeordnete Taxonomie';
return $choices;
}
add_filter('acf/location/rule_match/taxonomy_hierarchy', 'acf_location_rules_match_tax_hierarchy', 10, 3);
function acf_location_rules_match_tax_hierarchy( $match, $rule, $options )
{
if( !isset($_REQUEST['taxonomy']) OR !isset($_REQUEST['tag_ID'])) return false;
$term_depth = count( get_ancestors($_REQUEST['tag_ID'], $_REQUEST['taxonomy']) );
if($rule['operator'] == "==")
{
$match = ( ($rule['value'] == 'parent' AND $term_depth == 0) OR ($rule['value'] == 'child' AND $term_depth != 0) );
}
elseif($rule['operator'] == "!=")
{
$match = ( ($rule['value'] == 'parent' AND $term_depth != 0) OR ($rule['value'] == 'child' AND $term_depth == 0) );
}
//error_log(var_export($match, 1), 0);
return $match;
}
You must be logged in to reply to this topic.