The latest version, 4.3.1, resolves issue for my setup. Page with issue is now rendering exactly as with ACF 4.2.2.
My layout and loop sounds less complex than @Intervik’s. It is a single loop, which can run at most one time, and lists multiple posts containing the same set of custom fields.
Confirmation procedure:
@elliot, thanks for the quick turn-around on this.
BTW, any way to append version number on WordPress hosted file, e.g. “advanced-custom-fields-4.3.1.zip”? It helps to quickly identify needed version of file and fast to archive without extra edit (and chance of label error) on user’s part.
Peace
For my environment, I narrowed the issue down to the ACF core update alone (no other changes to WP and ACF add-on versions).
Working:
WP 3.6.1
ACF 4.2.2
ACF:Flexible Content Field 1.0.2
ACF:Repeater Field 1.0.1
ACF Repeater Collapser 1.1.0
ACF Support for Custom Post Templates 1.0
Custom Post Templates 1.5
Status after updating:
ACF 4.2.2 -> 4.3.0 :
Page renders differently as described in earlier post. has_sub_field returning false for specified repeater field.
Status after manual rollback:
ACF 4.3.0 -> 4.2.2 :
Page returns to expected rendering.
I searched for some keywords before reporting an issue submission and found this post.
The OP indicates similar behavior to what I am experiencing:
Use Case:
Code:`
$profile_pic = get_field('profile_pic', $post_id);
echo( “Post ID: ” . $post_id . “</br>”);
echo( “Profile_pic repeater field: “);
print_r($profile_pic);
echo “</br>”;
if (has_sub_field('profile_pic', $post_id)) {
$attachment_id = get_sub_field('media_library_image');
$url_link_image = get_sub_field('url_link_image');
…`
Debugging:
I narrowed the issue down to the has_sub_field() call. It returns false (every third post?!) even though print_r and var_dump statements to screen and log clearly show the repeater field has a sub_field.
*On pages where a single post is displayed, the image always shows.
*On the page where multiple posts are queried, every third image is blank.
After pure confusion for a few hours now, I also started to feel like the post_id is not “clearing” itself between new calls to has_sub_field.
Temporary work-around:
Since I know every post I am query has populated sub-fields, only solution (and risky one) is to directly access the array (e.g. $attachment_id = $profile_pic[0]["media_library_image"];
Everything shows up properly with this hack.)
General question:
How can I reset a call to has_sub_field so that I start again at first element of repeater field list (even if I have not reached end yet)? Sequential has_sub_field calls:`has_sub_field('profile_pic', $post_id
has_sub_field('profile_pic', $post_id)`
versus`has_sub_field('profile_pic', $post_id)
has_sub_field('profile_pic', $post_id)
has_sub_field('profile_pic', $post_id)`
produced an ON/OFF effect.
Environment:
WP 3.7.1
ACF 4.3.0
—–
Side note: I can understand the initial confusion OP may have with “note: you don’t need to specify the $post_id for any sub field functions” comment in documentation since has_sub_field is demonstrated both with and without use of the post_id parameter.
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.