Hey guys,
For some reason I wasn’t able to select proper page while I was settings up Location Rules for Fields Group. I had 3 pages, and the list returned me 2 correct and one Empty page.
I’ve jumped into the code and found a place where issue cased.
File: “/api/api-helpers.php”
Function: “acf_get_posts”
This piece:
// sort into hierachial order!
// this will fail if a search has taken place because parents wont exist
if( is_post_type_hierarchical($post_type) && empty($args['s'])) {
// vars
$match_id = $this_posts[ 0 ]->ID;
$offset = 0;
$length = count($this_posts);
// reset $this_posts
$this_posts = array();
// get all posts
$all_args = array_merge($args, array(
'posts_per_page' => -1,
'paged' => 0,
'post_type' => $post_type
));
$all_posts = get_posts( $all_args );
// 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++ ) {
$this_posts[] = acf_extract_var( $all_posts, $i);
}
}
The $offset value after “// loop over posts and find $i” was 1.
And because of this loop “for( $i = $offset; $i < ($offset + $length); $i++ )” the last array item for $this_posts was definitely empty, since it was looping out of the array boundaries.
Not sure what is that piece for and why such a loop exist there.. it can work only if $offset is 0, otherwise it will exceed the number of elements.
Anyways, I’ve changed the loop to “for( $i = 0; $i < $length; $i++ ) {” and it works fine now.
Can you check that part please? I’d love to be sure that the same issue won’t arise after plugin update.
Best,
Pavel.