Support

Account

Home Forums Feature Requests More specific location rules: nth-level page. Reply To: More specific location rules: nth-level page.

  • Thanks. This is exactly what I’m looking for.
    But it would be good if such a feature was available out of the box.

    // Edit;
    I found a little bug in the example you’ve provided. There’s a typo: isset($option['post_id'] instead of isset($options['post_id']

    // Edit 2;
    I’ve found another bug. $page_level doesn’t return a correct value.
    The logic is overcomplicated. It could be simplified:
    $page_level = count(get_post_ancestors($options['post_id'])) + 1; works fine.

    Here’s a fixed version: https://github.com/wujekbogdan/acf-filters-and-functions/blob/patch-1/page-nth-level-location-rule.php

    One more comment:
    There’s one disadvantage of this solution. acf/location/rule_operators filter doesn’t allow to set operators for a specific rule. It’s a general filter that applies for all the rules. But as far I know there’s no other option at the moment.