
Posts 2 Posts 1.4.1 each_connected bug
By:
certainlyakey on
Aug 24th, 2012 | syntax:
PHP | size: 0.64 KB | hits: 33 | expires: Never
<?php
$recentPosts = new WP_Query(array('showposts' => 5, 'post_type' => array('artist')));
p2p_type( 'posts_to_artists' )->each_connected( $recentPosts );
while( $recentPosts->have_posts() ) : $recentPosts->the_post(); ?>
//...
<?
// Display connected posts
if ($post->connected) {echo '<ul>';}
else {echo '<p>This artist has got no connected news items yet</p>';};
foreach ( $post->connected as $post ) : setup_postdata( $post );
?>
<li><a href="<? the_permalink(); ?>"><? the_title(); ?></a></li>
<? endforeach;
if ($post->connected) {echo '</ul>';};
wp_reset_postdata(); // set $post back to original post
?>