Skip to content

Using p2p_list_posts()

scribu edited this page Oct 27, 2011 · 8 revisions

p2p_list_posts() is an utility function that, as it's name suggests, outputs a list.

Here's how we could rewrite the Basic usage example:

<?php
// Find connected posts
$connected = p2p_type( 'posts_to_pages' )->get_connected( get_queried_object_id() );

// Display connected posts
if ( $connected->have_posts() ) :
	echo '<h3>Related posts</h3>';
	p2p_list_posts( $connected );
endif;
?>

To output links directly, without wrapping them in an unordered list, use:

p2p_list_posts( $connected, 'before_list=&after_list=&before_item= &after_item=' );