<?php
//Functions.php
function connect_posts2artists() {
// Make sure the Posts 2 Posts plugin is active.
if ( !function_exists( 'p2p_register_connection_type' ) )
return;
p2p_register_connection_type( array(
'name' => 'posts_to_artists',
'from' => 'post',
'to' => 'artist'
) );
}
add_action( 'wp_loaded', 'connect_posts2artists' );
?>
<?php
//Template file
$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
?>