Support

Account

Home Forums Backend Issues (wp-admin) Custom location rule operators not showing up in rule_match

Solved

Custom location rule operators not showing up in rule_match

  • Hello!

    I’m following this tutorial to set up custom location rules to display my field groups: https://www.advancedcustomfields.com/resources/custom-location-rules/

    This new field group aims to integrate WPML and ACF a little better, by showing the Field Group if a page is a translated version of another page. Example: Show this field group if page is Home OR page is a translated version of Home.

    I got really far actually, the problem is in the step 4 of the tutorial, in the rule_match. It doesn’t show my custom operator. This is what my operator code looks like:

    
    # Operators (step 2)
    function acf_location_rules_operators() {
        return array('translated_version' => 'is a translated version of');
    }
    add_filter('acf/location/rule_operators/wpml_page', 'acf_location_rules_operators');
    add_filter('acf/location/rule_operators/wpml_post', 'acf_location_rules_operators');
    

    The options look fine and work well:
    custom comparator not working acf

    The problem is in step 4 of the tutorial, when I try to validate if that field group should show up inside a page or not. I don’t see any “translated_version” operator:

    
    # Should we display this in a Page?
    function acf_location_rules_match_wpml_page( $match, $rule, $options ) {
        var_dump([$match, $rule, $options]);
    }
    add_filter('acf/location/rule_match/page', 'acf_location_rules_match_wpml_page', 1, 3);
    

    The code above outputs the following array in a page: https://pastebin.com/dvj2rink (PS: Post id for [Dutch] Home is 11)

    Question is: My operator “is_translated_version” shows up as an “==” when it goes through rule_match, that way, I don’t know what rule I’m comparing inside that function. Makes sense?

    Thanks a lot!!

  • I’m sorry, my mistake.

    I had wrong filters for rule_match. Here’s the right code:

    
    # Should we display this in a Page?
    function acf_location_rules_match_wpml_page( $match, $rule, $options ) {
        var_dump([$match, $rule, $options]);
    }
    add_filter('acf/location/rule_match/wpml_page', 'acf_location_rules_match_wpml_page', 1, 3);
    

    It works now.
    Thanks!

Viewing 2 posts - 1 through 2 (of 2 total)

The topic ‘Custom location rule operators not showing up in rule_match’ is closed to new replies.