<div class="title">Upcoming</div>
<?php
$today = date( 'Y-m-d' );
$posts = get_posts(array(
'post_type' => 'exhibition',
'posts_per_page' => -1,
'post_status' => ' published',
'meta_key' => 'date_debut',
'orderby' => 'meta_value_num',
'order' => 'DESC',
'meta_query' => array(
array(
'key' => 'date_debut',
'value' => $today,
'compare' => '>',
'type' => 'DATE'
),
)
)
);
if( $posts ): foreach( $posts as $post ):
$preserve_post = get_post();
?>
<div class="entry-content">
<p><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></p>
<?php
// Find connected pages
$connected = new WP_Query( array(
'post_type'=>'artist',
'connected_type' => 'posts_to_posts',
'connected_items' => $post,
'nopaging' => true,
) );
// Display connected pages
if ( $connected->have_posts() ) :
?>
<ul>
<?php while ( $connected->have_posts() ) : $connected->the_post(); ?>
<li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
<?php endwhile; ?>
</ul>
<?php
// Prevent weirdness
// wp_reset_postdata();
endif;
$post = $preserve_post;
setup_postdata( $post );
$datedebut = DateTime::createFromFormat('Ymd', get_field('date_debut'));
$datefin = DateTime::createFromFormat('Ymd', get_field('date_fin'));
echo $datedebut->format('d M, Y');?>-
<?php echo $datefin->format('d M, Y'); ?>
<p><?php echo the_field('emplacement'); ?></p>
</div>
<?php endforeach; ?>
<?php wp_reset_query(); ?>
<?php endif; ?>
hello this works for me..i make my first loop, i display the title of my event, and just after anoter loop to get the name of the related artist.i use $connected->the_post(); ?> and $post = $preserve_post;
setup_postdata( $post ); to keep the first loop , make another one, and come back to the first one..sorry for my bad english!!