Skip to content

Instantly share code, notes, and snippets.

@waltercruz
Created October 28, 2019 19:35
Show Gist options
  • Save waltercruz/2a2feab61a2d9f4cc967f4956215c35b to your computer and use it in GitHub Desktop.
Save waltercruz/2a2feab61a2d9f4cc967f4956215c35b to your computer and use it in GitHub Desktop.
<?php
add_filter('acf/location/rule_types', 'acf_location_rules_types');
function acf_location_rules_types($choices)
{
$choices['Menu']['menu_level'] = 'Nível do Menu';
return $choices;
}
add_filter('acf/location/rule_values/menu_level', 'acf_location_rule_values_level');
function acf_location_rule_values_level($choices)
{
$choices[0] = '0';
$choices[1] = '1';
return $choices;
}
add_filter('acf/location/rule_match/menu_level', 'acf_location_rule_match_level', 10, 4);
function acf_location_rule_match_level($match, $rule, $options, $field_group)
{
if ($rule['operator'] == "==") {
$match = ($options['nav_menu_item_depth'] == $rule['value']);
}
return $match;
}
@peteparsson
Copy link

I copied this to my functions.php -file and this makes new location rule but when I modify the navigation i get an error message Undefined array key "nav_menu_item_depth" Can you help me with this?

Br,
PeteP.

@waltercruz
Copy link
Author

hmmmm, I just tested this code and still works..

@peteparsson
Copy link

Yes code works but i also got an PHP error message. But i fixed it by adding conditional if ($rule['operator'] == "==" && isset($options['nav_menu_item_depth'])) { Sorry for bothering you and thank you for the code!

Br,
PeteP.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment