Support

Account

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:

    • after updating to 4.3.0 from 4.2.2 (and to latest FC and Rep add-ons from 1.0.2 and 1.0.1 respectively) a page now renders very differently. Specifically, media images stored as a sub-field in a repeater field are now showing blank due to has_sub_field function returning false semi-randomly.
    • I also came across “note: you don’t need to specify the $post_id for any sub field functions” in documentation. It appears in sample code on http://www.advancedcustomfields.com/resources/functions/has_sub_field/

    Use Case:

    1. Multiple posts created using the same ACF template.
    2. Gallery page loops through the posts to display them as a list.
    3. Every third post fails to show an image stored in the first sub-field (of two) of a repeater field.

    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.