Home Forums Front-end Issues have_rows() is spitting out errors if it doesn't find the field.


have_rows() is spitting out errors if it doesn't find the field.

  • Ever since upgrading various sites to ACF PRO v5.1.1 I’ve been having fairly major issues with have_rows().


    Let’s say we have a repeater field that outputs a simple list, with the id ‘list_field’.

    For pages with entries in ‘list_field’, have_rows() finds the entries and it displays the content as expected.

    However for pages where ‘list_field’ is either empty or isn’t even present, I get the following error (I censored the URL):

    Warning: array_key_exists() expects parameter 2 to be array, boolean given in SERVERURLHERE/wp-content/plugins/advanced-custom-fields-pro/api/api-helpers.php on line 846

    This is a real example of code causing the error:

    <?php if( have_rows('flexible_rows') ): ?>
        <div class="flexible-rows">
            <?php while( have_rows('flexible_rows') ): ?>
            <?php endwhile; ?>
    <?php endif; ?>

    Even if I comment out the ‘if’ and ‘endif’ lines it still errors, which I assume is on the have_rows() in the while.

    For reference, this is within the loop in a CPT single template. So explicitly specifying the ID shouldn’t be necessary.

    I’ve had a brief look through the various ‘issues’ sub-forums here and haven’t come across anything, which strikes me as strange as this issue is present on every site that I’ve updated to v.5.1.1 on and I had assumed more people would have noticed it.

    Any ideas?

  • In addition to what you just described. If you just do an empty update of the offending post. The error goes away.

    Others are discussing it here:

  • Thank you for the response.

    Unfortunately I can’t seem to get the error to go away. Maybe I’m mis-understanding what you mean by ‘offending post’?

    I am getting the error in various places on the website I’m working on right now:

    • I’m getting on 4/5 of my ‘Services’ pages (CPT ‘single-rp_service.php’) where the 5th one has the repeater field filled in and the other 4 has it empty. I have updated all 5 of the posts and the issue persists.
    • I am also getting in footer.php with the same repeater field ‘flexible_rows’, it also didn’t update here when I updated the 1 service page which uses the field.

    At this point I’ve updated every page on my site and the error persists.

    Any thoughts much appreciated.

  • Offending Post would be the post which has the repeater with no values (empty). In the case you have described above, it would be the 4/5 posts.

    As you said you have tried updating the CPTs and the issue persists, so I guess the temporary fix does not work for you. It seems to have worked for other people, perhaps you have implemented the code differently.

    Also check the reply on the other thread linked above.

  • This reply has been marked as private.
  • Hey, thanks for letting me know.

    I just noticed the version tags on the thread, that’s a neat additional. I will tag the ACF version in any future threads.

  • This reply has been marked as private.
Viewing 7 posts - 1 through 7 (of 7 total)

The topic ‘have_rows() is spitting out errors if it doesn't find the field.’ is closed to new replies.