Support

Account

Home Forums General Issues ACF Galleries displaying empty

Solving

ACF Galleries displaying empty

  • Hello & good day!

    On our WordPress website (with the ACF plugin & custom theme using this), we have had some issues with Advance Custom Fields galleries in that they occasionally appear, but appear with no content. This is not what we want, obviously.

    We have 3 galleries displayed on every page of our website (you can see for yourselves at uniqueteambuilding.com.au with the titles “As Seen On”, “Our Happy Clients”, “Testimonials”) at the footer.

    Sometimes these galleries work fine, and other times they don’t – it changes each time you refresh and/or change page. I have noticed that all 3 of these galleries are either all not working at once or are all working at once.
    And when they are working, the image thumbnails of that page do not load & when they’re not working the image thumbnails are working.

    When (and only when) these galleries are not appearing, the debug.log gives PHP Warnings of; “Invalid argument supplied for foreach()” about each of these galleries (one warning for each gallery). These errors point to following code (for each of the galleries):

    <h3 class=”text-center”><?php the_field(‘as_seen_on_block_title’, “options”) ?></h3>
    <?php if ($logos = get_field(“as_seen_on_logos”, “options”)): ?>
    <ul class=”slider-as-seen-on”>
    <?php foreach ($logos as $logo) {…

    <h3 class=”text-center”><?php the_field(‘logo_block_title’, “options”) ?></h3>
    <?php if ($logos = get_field(“logos”, “options”)): ?>
    <ul class=”logos”>
    <?php foreach ($logos as $logo) {…

    <?php if ($testimonials = get_field(“testimonial_list”, “options”)): ?>
    <ul id=”testimonials” class=”bxslider”>
    <?php foreach ($testimonials as $testimonial) {…

    When the galleries load fine, no such warnings are given. So I’m assuming that this is the issue here.

    I believe this means that the fields aren’t set as (or being passed as) arrays, which would be preferred. I checked the ACF output log and saw that it was passed as arrays (although that may have only been when it was working). Perhaps when the galleries are not working, null is being passed to it & so that error is also thrown.

    It could also be a caching issue, which would make sense with the thumbnails not working… We would also love any advice on the thumbnails too if you know anything? It also used ACF functions but does not return any PHP warnings or errors. Here is the code for loading the thumbnails;

    <?php $image = wp_get_attachment_image_src(get_field(‘event_thumbnail’), ‘full’); ?>
    ” alt=”<?php echo get_the_title(get_field(‘event_thumbnail’)) ?>” />

    I’m not too sure where to go from here, I’ve spent a long time trying to figure this out & fix it but haven’t gotten very far. So any help & advice would be amazing!!

    Thanks very much!
    Aidan

  • This will always be true

    
    if ($logos = get_field("as_seen_on_logos", "options")): 
    

    true or false in this case is dependent of if a value is assigned to $logos and that will always happen even if the field has no value.

    You need to get the value and then test the value, as far as I know you cannot do this all in the if, to test you can also display the value to make sure you’re getting what you expect.

    
    $logos = get_field('as_seen_on_logos', 'options');
    echo '<pre>'; var_dump($logos); echo '</pre>'; // test
    if (!empty($logos)) {
      // loop over logos
    }
    
  • Hi John!

    Thanks for this, I have just tried that myself but it had no effect, unfortunately. But I have figured out much more about this and have created a new post here;

    https://support.advancedcustomfields.com/forums/topic/get_field-occassionally-returning-string-with-repeater-field/

    Apologies for the inconvenience.

Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic.