Home › Forums › Bug Reports › [5.0.x] Most pages don't show up when adding a rule to target a specific page
I’m trying to create a field group and set a rule to short by a specific Page. The dropdown that shows the available pages is severely limited. The valeus being posted:
action acf/field_group/render_location_value
group_id group_0
nonce a201e364d4
param page
rule_id rule_0
value
Following this, it seems there’s an issue with this part of acf_get_posts in api-helpers.php:
// order posts
$all_posts = get_page_children( 0, $all_posts );
for( $i = $offset; $i < ($offset + $length); $i++ ) {
$this_posts[] = acf_extract_var( $all_posts, $i);
}
Starting with $offset cuts off a large portion of the list off. For example, if offset is 21 and length is 23, I only get two results back and then a bunch of blanks:
Array
(
[0] => WP_Post Object
( ... )
[1] => WP_Post Object
( ... )
[2] =>
[3] =>
[4] =>
[5] =>
[6] =>
[7] =>
[8] =>
[9] =>
[10] =>
[11] =>
[12] =>
[13] =>
[14] =>
[15] =>
[16] =>
[17] =>
[18] =>
[19] =>
[20] =>
[21] =>
[22] =>
)
Taking out that for loop and just setting $this_posts = $all_posts; fixes it.
Also still broken in 5.0.7. The fix as listed above still works.
Actually, following http://support.advancedcustomfields.com/forums/topic/5-0-7-pro-pagesposts-not-showing-in-rules/, it does seem to be related to Post Types Order. When I deactivate that plugin, it works fine.
Okay, figured it out.
The error is in acf_get_posts() and the $offset variable:
$offset = 0;
// ...
// loop over posts and find $i
foreach( $all_posts as $offset => $p ) {
if( $p->ID == $match_id ) {
break;
}
}
// order posts
$all_posts = get_page_children( 0, $all_posts );
for( $i = $offset; $i < ($offset + $length); $i++ ) {
$offset is used in the foreach loop, which then breaks it when trying to do the for loop at the end. Changing $offset => $p
to $postOffset => $p
, or even just => $p
, solves the issue.
Fix above also works for me. I havn’t tried turning off Post Types Order because I need it installed but hopefully this collision between the plugins gets solved.
For me, either the fix above or disabling the PTO plugin will solve the issue. I also would like this fixed before the next ACF update, so that my temp fix won’t be overridden and create more problems.
And mucho thanks to @gregatetr for all that bug solving, saved me a LOT of time! 🙂
The topic ‘[5.0.x] Most pages don't show up when adding a rule to target a specific page’ is closed to new replies.
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.