Support

Account

Home Forums General Issues Loop to display ACF Image field from custom post type

Solved

Loop to display ACF Image field from custom post type

  • Hello ACF community !
    I started experimenting with ACF (free) a few days ago. I created a custom post type with one ACF image field. I confess I’m trying to make a gallery out of that.
    Using that thread that was (very) useful for my situation.

    I made a loop to display the content of that CPT ‘escaliers‘: a single image field called ‘portfolio‘.

    <?php
    get_header();
    $args = array(
        'numberposts'	=> -1,
        'post_type'		=> 'escaliers',
    );
    $the_query = new WP_Query( $args );?>
    <?php if( $the_query->have_posts() ): ?>
        <figure class="wp-block-gallery columns-3 is-cropped row">
            <ul class="blocks-gallery-grid">
                <?php while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
                    <li class="blocks-gallery-item">
                        <figure>
                            <img width="1024" height="765" src="<?php the_field('portfolio') ?>">
                        </figure>
                    </li>
                <?php endwhile; wp_reset_postdata(); ?>
            </ul>
        </figure>
    <?php endif; ?>
    <?php wp_reset_query();	 // Restore global post data stomped by the_post(). ?>
    <?php get_footer(); ?>

    It worked like a charm until this morning when img src in the DOM are filled with “src(unknown)”. Should I use the custom post type ID to refer to the image field ?
    If not the template, could have it been from the switch to https or the installation of a cache extension ?

  • Illustration of the broken loop
    I forgot to specify that only the img link is broken since the loop still displays the correct number of custom post from that slug. As you can see in that screenshot.
    The ACF image return format is set to URL.

  • Did you check the Link of the images (is the path wrong?) or used the dev tools to have a look at the images? Looks like it is not an ACF thing because the right amount of images is added to your html code.

  • Hi @Flaschenzug,
    Thank you for your answer ! The issue came from the SSL certificate that expired on the 1st of october, a few hours after I experimented with that. It’s now fixed and this code is working again.

    I asked myself the same questions but didn’t get much debug information, with devtools the src in image tag wasn’t filled with the image link and no error would come up. I did check if all the links in medias were in https and they were.
    I don’t have much knowledge in the server side but I guess it wouldn’t let wordpress process https links when its SSL certificate is expired.

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

You must be logged in to reply to this topic.