Home › Forums › General Issues › Use post object in a loop of a custom post type › Reply To: Use post object in a loop of a custom post type
<?php wp_reset_postdata(); ?>
↓
<?php $loop->reset_postdata(); ?>
<?php $loop = new WP_Query($args); ?>
<?php if ( $loop->have_posts() ) : while ( $loop->have_posts() ) : $loop->the_post(); ?>
<?php
// HERE STARTS THE POST OBJECT PART TO SHOW DATA FROM THE LINKED POST
$post_object = get_field('kurs_zu_diesem_seminar');
if( $post_object ):
// override $post
$post = $post_object;
setup_postdata( $post );
?>
<h3><a>"><?php the_title(); ?></a></h3>
<?php $loop->reset_postdata(); ?>
<?php endif; ?>
// END POST OBJECT PART
// START SHOW DATA FROM DEFAULT OBJECT
<span class="title"><?php the_title(); ?> am <?php the_field('start_datum'); ?></span>
<?php the_field('beschrieb'); ?>
<?php endwhile; ?>
<?php else: ?>
<p>Aktuell sind keine Seminare geplant.</p>
<?php endif; ?>
<?php wp_reset_postdata(); ?>
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!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.