Pull image from ACF field in a Custom Post Type

Question

Hopefully, I can explain this well enough, but let me know if not and I’ll expand on it.

I’ve used ACF in conjunction with a Custom Post Type, but when I try to grab the photo that I’ve uploaded for each product it only shows the photo for the first product each time for all products on the archive-products.php page.

<?php 
    $args = array( 'post_type' => 'products', 'posts_per_page' => 9 );
    $the_query = new WP_Query( $args );

    $landscape = get_field('main_photo_landscape', $post->ID);
?>

<main class="site-content">
    <div class="row">

        <?php if ( $the_query->have_posts() ) : ?>
            <?php while ( $the_query->have_posts() ) : $the_query->the_post(); ?>

                <article class="col-12 col-md-6 col-lg-4 product">
                    <a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>">
                        <div class="featured-img" style="background: url('<?php echo $landscape['sizes']['large']; ?>') center center no-repeat; background-size: auto 100%"></div>
                        <h1 class="title"><?php the_title(); ?></h1>
                        <button class="btn">More Details</button>
                    </a>
                </article>

            <?php endwhile; ?>

            <?php the_posts_navigation(); ?>

        <?php endif; ?>

    </div>
</main>
0
, Dan 3 years 2020-04-02T16:51:16-05:00 0 Answers 85 views 0

Leave an answer

Browse
Browse