Support » Plugin: Posts 2 Posts » [Plugin: Posts 2 Posts] Using each_connected multiple times isn't working

  • Hey,

    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.
    `
    <?php
    $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(); ?>
    <p>The Recipe</>
    <?php the_title(); ?>

    <?php
    // Display connected tip

    echo ‘<p>Tip:</p>’;

    foreach ( $post->tips as $post ) : setup_postdata( $post );
    the_title();
    endforeach;

    wp_reset_postdata();

    // Display connected chef
    echo ‘<p>Chef:</p>’;
    foreach ( $post->chefs as $post ) : setup_postdata( $post );
    the_title();
    endforeach;

    wp_reset_postdata();
    ?>

    <?php endwhile; ?>
    `

    http://wordpress.org/extend/plugins/posts-to-posts/

  • The topic ‘[Plugin: Posts 2 Posts] Using each_connected multiple times isn't working’ is closed to new replies.