Home Forums Front-end Issues Post Object: Only Returns One CPT


Post Object: Only Returns One CPT

  • Hello, trying to list out 4 CPT post objects to my ‘category-distributions.php’ archive page. I am using the first of the two options on the “Display data for multiple post objects” section at “Post Object” page.
    I would like to show the post thumbnail and the excerpt/content. I’ve put most of it together, and I feel really close because one of the posts will show, but only one. Here is my code:

    <?php if (is_category('distributions')) :?>
                                $post_objects = get_field('distribution_post_01');
                                if ($post_objects):
                                    // echo '<pre>';
                                    //     print_r($post_objects);
                                    // echo '</pre>';
                                    // die;
    							    <?php foreach ($post_objects as $post): // variable must be called $post (IMPORTANT)?>
    							        <?php setup_postdata($post);
    									<div class="cell medium-3">
    										<a href="<?php the_permalink(); ?>">
    											<!-- Hook up Interchange as an img src -->
    											<div class="callout callout-hover-reveal" data-callout-hover-reveal>
    												<div class="callout-body">
    													<img class="cell medium-6 category-feat" data-interchange="[<?php the_post_thumbnail_url('fp-small'); ?>, small], [<?php the_post_thumbnail_url('fp-medium'); ?>, medium], [<?php the_post_thumbnail_url('fp-large'); ?>, large], [<?php the_post_thumbnail_url('fp-xlarge'); ?>, xlarge]">
    													<noscript><img src="<?php the_post_thumbnail_url(); ?>" alt="<?php echo $alt_text; ?>" /></noscript>
    												<div class="callout-footer">
    													<p><?php the_field('synopsis'); ?></p>
    							    <?php endforeach;
    							    <?php wp_reset_postdata(); // IMPORTANT - reset the $post object so the rest of the page works correctly?>
    							<?php endif; ?>
    					<?php endif;?> <!-- END category is distributions -->

    I feel like I’m really close! Thank you for your help!

Viewing 1 post (of 1 total)

The topic ‘Post Object: Only Returns One CPT’ is closed to new replies.