Support

Account

Home Forums General Issues Get Gallery Field no view images from another post

Solving

Get Gallery Field no view images from another post

  • Hi,
    I use acf field for page’s gallery and the code below shows it perfecty:

    
    <?php if ( get_field('imggal') ) { ?> 
        <div class="galleria">
            <?php echo get_field('imggal'); ?>  
        </div>
    <?php } ?>
    

    I want to limit number of images in preview (in slideshow I’ll see all images).
    I installed “Limit parameter for gallery shortcode” plugin to do this and in my template file I do:

    
    <?php if ( get_field('imggal') ) { ?> 
        <div class="galleria">
        <?php 
        $image_ids = get_field('imggal', false, false);
        $shortcode = '[gallery limit="3" columns="3" order="ASC" orderby="menu_order ID" ids="' . implode(',', $image_ids) . '"]';
        echo do_shortcode( $shortcode );
        ?>      
        </div>
    <?php } ?>  
    

    It work perfecty too but only if images are attached into the post, not from another post.

    How can I do to view also images from another post?

  • Hi @donnafefe

    The gallery shortcode should be able to show images even if they’re not connected to the post if you pass along image ids.

    However are you aware that you need to set the second parameter of get_field to the other posts ID if you want to fetch them from another post?

    
    <?php if ( get_field('imggal', $other_post_id) ) { ?> 
        <div class="galleria">
        <?php 
        $image_ids = get_field('imggal', $other_post_id, false);
        $shortcode = '[gallery limit="3" columns="3" order="ASC" orderby="menu_order ID" ids="' . implode(',', $image_ids) . '"]';
        echo do_shortcode( $shortcode );
        ?>      
        </div>
    <?php } ?>
    
  • Hi Jonathan,
    I want not to get images from a specific other post, but I want select from image library…

    In post 55 I created a gallery with acf field and I selected 5 images connected to other post and 1 image uploaded in that post (55)…

    I view 6 images with:
    <?php echo get_field('imggal'); ?>

    with the other solution I view only 1 image, the only one connected with that post (55)

    sorry for my english 😛

  • Hi @donnafefe

    Make sure that you’re actually just getting image ids with this:
    $image_ids = get_field('imggal', false, false);
    Also, does it work with the limit plugin deactivated? Maybe it also limits images to those uploaded to the post.

    In the end it seems more like an issue/bug with the gallery shortcode in WordPress than ACF. If you truly are getting all 6 attachment IDs with the above code ACF is doing it’s part correctly.

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

The topic ‘Get Gallery Field no view images from another post’ is closed to new replies.