I am trying to show Images using custom fields. But it’s not working. Can you check.
Below is the code
<?php
// Show the Gallery
if( have_rows(‘gallery_slideshow’) ):
echo ‘<div class=”projects-gallery-wrap”>’;
echo ‘<div class=”projects-gallery”>’;
// loop through the rows of data
while ( have_rows(‘gallery_slideshow’) ) : the_row();
$imgObj = get_sub_field(‘image’, $post->ID);
echo ‘
‘;
endwhile;
echo ‘</div>’;
echo ‘</div>’;
endif;
?>
http://divinepower.co.in/cof/projects/contract/waikiki-honolulu/
The same code is working okay on different custom post type.

Hi Sargamgupta,
It’s quite hard to read your code, if you highlight it and select the ‘code’ button on the menu above the text box it will display it in a nicer format and make it easier for people to help you đ
It looks like you are returning the alt tag for the image rather than the url, try this instead;
<?php echo $imgObj['url']; ?>
You may want to separate your markup from your PHP which will make it again easier to understand, and also wrap and img tag around your output –
<?php // Show the Gallery
if( have_rows(âgallery_slideshowâ) ): ?>
<div class="projects-gallery-wrap">
<div class="projects-gallery">
<?php // loop through the rows of data
while ( have_rows(âgallery_slideshowâ) ) : the_row(); ?>
<?php $imgObj = get_sub_field(âimageâ, $post->ID); ?>
<img src="<?php echo $imgObj[url]; ?>" alt="<?php echo $imgObj[alt]; ?>">
<?php endwhile; ?>
</div>
</div>
<?php endif; ?>
You may also want to check you are outputting the image object and not the URL/ID in the backend.
Let me know how it goes.
Hi @sargamgupta
Just chiming in on another thing. The get_sub_field()
function does not need (nor take) a second parameter of the post id so please remove that. You’ll only need the field name as a single parameter in any get_sub_field()
or the_sub_field()
.