Support

Account

Home Forums Feature Requests Conditional Logic on Menu Item Reply To: Conditional Logic on Menu Item

  • This should work:

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