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.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.