Support

Account

Home Forums Add-ons Gallery Field Display correctly ACF gallery as wordpress gallery

Solved

Display correctly ACF gallery as wordpress gallery

  • Hello everyone, I am writing to you because I have a display problem on acf gallery.
    I create a gallery with wordpress and I see it correctly.
    I create a gallery with ACF gallery and the images are not displayed as with worpress. where am I wrong? I am attaching the link and the code I use.
    thank you all

    http://www.ilnuovoweb.it/topsito/share/gallery.jpg

    this is the code I use

    <?php $gallery_images = get_field( ‘gallery’ ); ?>
    <?php if ( $gallery_images ) : ?>
    <?php foreach ( $gallery_images as $gallery_image ): ?>
    “>
    ” alt=”<?php echo $gallery_image[‘alt’]; ?>” />

    <p><?php echo $gallery_image[‘caption’]; ?></p>
    <?php endforeach; ?>
    <?php endif; ?>

  • If you want to show the gallery the same way that wp does then

    
    $gallery_images = get_field('gallery', false, false);
    echo do_shortcode('[gallery ids="'.implode(',',$gallery_images).'"]');
    

    this is one of the examples given in the gallery field documentation https://www.advancedcustomfields.com/resources/gallery/

  • thanks for the reply, I tried to enter this code but it does not work properly for me.
    I receive this error:

    Warning: implode(): Invalid arguments passed in /home/mhd-01/www.ilnuovoweb.it/htdocs/topsito/wp-content/themes/mh-magazine/single.php on line 11

    modifying in:
    $gallery_images = get_field(‘gallery’, false, false);
    echo do_shortcode(‘[gallery ids="'.'"]‘);

    the error disappears, but the problem is that if I delete images from the gallery in the front end we continue to see, even if I delete the cache

  • You need to check the value that your passing to implode. It should be an array of image IDs. The code looks right. The shortcode must have the list of IDs or is just shows all images attached to the post.

  • Thank you so much I solved it, now it seems to work properly

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

You must be logged in to reply to this topic.

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 Cookie Policy. If you continue to use this site, you consent to our use of cookies.