Home › Forums › Add-ons › Flexible Content Field › Latest version: critical endless loop crashes sites › Reply To: Latest version: critical endless loop crashes sites
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.