In case someone needs it this works well as long as a portfolio item is not in two categories …
The question is: can you know from which portfolio page you are calling?
For example: Cat1, Cat2 and item porfolio Item1
If from the portfolio page that groups all the items from cat1 we call the item1 that is in two categories, I can know that I come from Cat1?
function x_entry_navigation() {
$stack = x_get_stack();
$entry_id = get_the_ID();
if ( $stack == 'ethos' ) {
$left_icon = '<i class="x-icon-chevron-left" data-x-icon-s=""></i>';
$right_icon = '<i class="x-icon-chevron-right" data-x-icon-s=""></i>';
} else {
$left_icon = '<i class="x-icon-arrow-left" data-x-icon-s=""></i>';
$right_icon = '<i class="x-icon-arrow-right" data-x-icon-s=""></i>';
}
/* Terms */
$terms = get_the_terms( get_the_ID(), 'portfolio-category' );
/* Slugs */
$slugs = array();
foreach ( $terms as $term ) {
$slugs[] = $term->slug;
}
$wp_query = new WP_Query( array(
'post_type' => 'x-portfolio',
'posts_per_page' => -1,
'tax_query' => array(
array (
'taxonomy' => 'portfolio-category',
'field' => 'slug',
'terms' => $slugs,
)
),
) );
/* Save ID's same slugs */
$ids = array();
while ( $wp_query->have_posts() ) {
$wp_query->the_post();
$ids[] = get_the_ID();
}
wp_reset_postdata();
$thisindex = array_search( $entry_id, $ids );
$prev_post = isset( $ids[ $thisindex - 1 ] ) ? $ids[ $thisindex - 1 ] : 0;
$next_post = isset( $ids[ $thisindex + 1 ] ) ? $ids[ $thisindex + 1 ] : 0;
$is_ltr = ! is_rtl();
//$prev_post = get_adjacent_post( false, '', false );
//$next_post = get_adjacent_post( false, '', true );
$prev_icon = ( $is_ltr ) ? $left_icon : $right_icon;
$next_icon = ( $is_ltr ) ? $right_icon : $left_icon;
?>
<div class="x-nav-articles">
<?php if ( $next_post ) : ?>
<a href="<?php echo get_permalink( $prev_post ); ?>" title="<?php __( 'Previous Post', '__x__' ); ?>" class="prev">
<?php echo $prev_icon; ?>
</a>
<?php endif; ?>
<?php if ( $next_post ) : ?>
<a href="<?php echo get_permalink( $next_post ); ?>" title="<?php __( 'Next Post', '__x__' ); ?>" class="next">
<?php echo $next_icon; ?>
</a>
<?php endif; ?>
</div>
<?php
}
?>