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')) :?> <?php $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> <div class="callout-footer"> <p><?php the_field('synopsis'); ?></p> </div> </div> </a> </div> <?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!
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!
📣 “ACF Chat Fridays”— Advanced Custom Fields (@wp_acf) January 31, 2023
The ACF team holds their first open office hours this Friday! Come and talk ACF, and ask questions about building sites with the plugin.
We’d love to see you there!
📆 Friday 3rd Feb - 3pm UTC
👉 Register here - https://t.co/3UtvQbE4CU pic.twitter.com/oTwW9K1XQ0
© 2023 Advanced Custom Fields.