Skip to content

Get adjacent items

dawnbuie edited this page Mar 9, 2013 · 7 revisions

The get_adjacent_items() function takes the ID of the current post and returns the WP_Post objects for the previous and next sibling items and for the parent items.

<?php
$items = p2p_type('posts_to_series')->get_adjacent_items( $episode_id );

echo '<br> parent: '. get_permalink( $items['parent'] ); 

if ( $items['previous'] )
echo '<br> previous: ' . get_permalink( $items['previous'] );

if ( $items['next'] )
echo '<br> next: ' . get_permalink( $items['next'] );
?>
Clone this wiki locally