Home › Forums › General Issues › 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.
You must be logged in to reply to this topic.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
Are you building WordPress sites with ACF and @BeaverBuilder, and wanted to use your ACF Blocks in both the block editor and Beaver Builder?
— Advanced Custom Fields (@wp_acf) May 10, 2023
The BB team recently added support for using ACF Blocks in Beaver Builder. Check it out 👇https://t.co/UalEIa5aQi
© 2023 Advanced Custom Fields.
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.