Support

Search results for ""

Sorry, no results found. Perhaps you would like to search the documentation?
All Topics
Daniel

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;
}

4 years, 7 months ago
Stefan
Developer

Hi Daniel,

This is currently not available.
Only rules that apply to the complete overview (instead of specific posts) works with the ACF addon.
But I believe it works when you have at least one rule that is set for the complete overview, like ‘Taxonomy’ = ‘category’ where the rest of the location rules contains exceptions.

We have looked into this but we chose to make a solution that works for most of the ACF setups. All our features like inline edit, sorting and inline edit works by default for all posts in a overview without restriction so building in restriction for ACF would not work in our core.

4 years, 7 months ago
Daniel

ok, thanks for letting me know.
it’s not an urgent matter but it would be nice to get this working sometime in the near future, if you find a way.

4 years, 7 months ago

You must be logged in to reply to this topic.