Pastebin launched a little side project called VERYVIRAL.com, check it out ;-) Want more features on Pastebin? Sign Up, it's FREE!
Guest

Posts 2 Posts 1.4.1 each_connected bug

By: certainlyakey on Aug 24th, 2012  |  syntax: PHP  |  size: 0.64 KB  |  views: 41  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. <?php
  2.                 $recentPosts = new WP_Query(array('showposts' => 5, 'post_type' => array('artist')));
  3.                 p2p_type( 'posts_to_artists' )->each_connected( $recentPosts );
  4.                         while( $recentPosts->have_posts() ) : $recentPosts->the_post(); ?>
  5. //...
  6. <?
  7.                 // Display connected posts
  8.                 if ($post->connected) {echo '<ul>';}
  9.                 else {echo '<p>This artist has got no connected news items yet</p>';};
  10.                 foreach ( $post->connected as $post ) : setup_postdata( $post );
  11. ?>
  12.                 <li><a href="<? the_permalink(); ?>"><? the_title(); ?></a></li>               
  13. <?              endforeach;
  14.                 if ($post->connected) {echo '</ul>';};
  15.                 wp_reset_postdata(); // set $post back to original post
  16. ?>