First off, thanks a lot for the plug-in – seems perfect for what I’m trying to do.
I modified the Looping the Loop example (https://github.com/scribu/wp-posts-to-posts/wiki/Looping-The-Loop) for using each_connected multiple times.
I have 3 cpt – recipes, tips and chefs. For each recipe I’m trying to display information about the connected tips and chefs.
In the code below, the recipe title and tip title appear, but nothing appears for the chef posts. If I comment out the foreach & wp_reset_postdata() code for the tip posts, then the chef post data does appear. I’m totally stumped on this one so any help would be greatly appreciated!
The code is either http://pastebin.com/yz7gfUVY or below.
$my_query = new WP_Query( array(
‘post_type’ => ‘recipes’
p2p_type( ‘recipes_to_tips’ )->each_connected( $my_query, array(), ‘tips’ );
p2p_type( ‘recipes_to_chefs’ )->each_connected( $my_query, array(), ‘chefs’ );
<?php while ( $my_query->have_posts() ) : $my_query->the_post(); ?>
<?php the_title(); ?>
// Display connected tip
foreach ( $post->tips as $post ) : setup_postdata( $post );
// Display connected chef
foreach ( $post->chefs as $post ) : setup_postdata( $post );
<?php endwhile; ?>
- The topic ‘[Plugin: Posts 2 Posts] Using each_connected multiple times isn't working’ is closed to new replies.