Skip to content

Instantly share code, notes, and snippets.

@fael
Created August 14, 2013 05:16
Show Gist options
  • Save fael/6228203 to your computer and use it in GitHub Desktop.
Save fael/6228203 to your computer and use it in GitHub Desktop.
Get adjacent posts from a term of a custom taxonomy
<?php
function next_prev_portfolio($post, $current_term){
//echo '<pre>';
$postlist_args = array(
'posts_per_page' => -1,
//'orderby' => 'menu_order title',
//'order' => 'ASC',
'post_type' => 'portfolio',
'portfolio_category' => $current_term
);
$postlist = get_posts( $postlist_args );
$ids = array();
foreach ($postlist as $thepost) {
$ids[] = $thepost->ID;
}
$thisindex = array_search($post->ID, $ids);
$previd = $ids[$thisindex-1];
$nextid = $ids[$thisindex+1];
if ( !empty($previd) ) {
echo '<a class="styled-link next-link" title="' . get_the_title($previd) . '" href="' . get_permalink($previd). '"><span>&nbsp;</span></a>';
}
if ( !empty($nextid) ) {
echo '<a class="styled-link prev-link" title="' . get_the_title($nextid) . '" href="' . get_permalink($nextid). '"><span>&nbsp;</span></a>';
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment