Advertisement
Guest User

Posts-To-Posts Multiple each_connected()

a guest
Aug 12th, 2012
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.14 KB | None | 0 0
  1.               <?php
  2.                 $my_query = new WP_Query( array(
  3.                   'post_type' => 'recipes'
  4.                 ) );
  5.  
  6.                 p2p_type( 'recipes_to_tips' )->each_connected( $my_query, array(), 'tips' );
  7.  
  8.                 p2p_type( 'recipes_to_chefs' )->each_connected( $my_query, array(), 'chefs' );
  9.               ?>
  10.  
  11.               <?php while ( $my_query->have_posts() ) : $my_query->the_post(); ?>
  12.                 <p>The Recipe</>
  13.                 <?php the_title(); ?>
  14.  
  15.                 <?php
  16.                   // Display connected tip
  17.                  
  18.                   echo '<p>Tip:</p>';
  19.                
  20.                   foreach ( $post->tips as $post ) : setup_postdata( $post );
  21.                     the_title();
  22.                   endforeach;
  23.  
  24.                   wp_reset_postdata();
  25.  
  26.  
  27.                   // Display connected chef
  28.                   echo '<p>Chef:</p>';
  29.                   foreach ( $post->chefs as $post ) : setup_postdata( $post );
  30.                     the_title();
  31.                   endforeach;
  32.  
  33.                   wp_reset_postdata();
  34.                 ?>
  35.  
  36.               <?php endwhile; ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement