Clicking on the images here reveals 'next' and 'previous' arrows on each image, except the first two. What could be causing this issue?
<nav class="prev-next">
<ul>
<?php
$next_post = get_next_post();
$prev_post = get_previous_post();
$next_post_year = '';
$previous_post_year = '';
$previous_post_media = '';
$next_post_media = '';
if($next_post) {
$next_post_id = ($next_post->ID);
$years = wp_get_post_terms( $next_post_id, 'years', array( 'fields' => 'ids' ) );
$medias = wp_get_post_terms( $next_post_id, 'media', array( 'fields' => 'ids' ) );
$next_post_year = $years[0];
$next_post_media = $medias[0];
}
if($prev_post) {
$previous_post_id = ($prev_post->ID);
$years = wp_get_post_terms( $previous_post_id, 'years', array( 'fields' => 'ids' ) );
$medias = wp_get_post_terms( $previous_post_id, 'media', array( 'fields' => 'ids' ) );
$previous_post_year = $years[0];
$previous_post_media = $medias[0];
}
$show_next = false;
if($next_post_year == $current_post_year && $next_post_media == $current_post_media) {
$show_next = true;
}
$show_prev = false;
if($previous_post_year == $current_post_year && $previous_post_media == $current_post_media) {
$show_prev = true;
}
?>
<?php /*<li class="prev"><?php previous_post('%', '‹ Previous', 'no'); ?></li>
<li class="next"><?php next_post('%' , 'Next ›', 'no'); ?></li>*/ ?>
<?php if($show_next) { ?>
<li class="prev"><?php next_post('%' , '‹ Previous', 'no'); ?></li>
<?php } ?>
<?php if($show_prev) { ?>
<li class="next"><?php previous_post('%', 'Next ›', 'no'); ?></li>
<?php } ?>
</ul>
</nav>
Inspecting the code of the single image pages not displaying arrows shows that the next and previous <li>
elements are not being generated on those specific pages.