0

I am using a custom post type with a custom taxonomy. I am trying to show prev/next pagination on the single, but I want it to limit it to CPT posts that are in the same custom taxonomy.

Here's where it gets weird. If I customize get_previous_post with the following

get_next_post($format, $link, $in_same_term = true, $excluded_terms = '', $taxonomy = 'webinar_type');

it works just fine and if I customize get_next_post with the same parameters, it also works. But when I customize BOTH get_next_post and get_prev_post with the same parameters, nothing is output at all.

Here is the full non-working code. Nothing is output.

<div class="navigation news_single et_pb_animation_bottom et-waypoint et_animated et-animated">
<?php 
$prev_post = get_previous_post($format, $link, $in_same_term = true, $excluded_terms = '', $taxonomy = 'webinar_type');
if (!empty( $prev_post )) {
    $prev_post_ID = $prev_post->ID;
    $prev_post_link = get_permalink($prev_post_ID);
    $prev_post_title = get_the_title($prev_post_ID);
    $prev_post_bolded_title = get_field('bolded_title', $prev_post_ID);
    $prev_post_subtext = get_field('subtext', $prev_post_ID);
    if($prev_post_bolded_title || $prev_post_subtext ) {
        $title = $prev_post_bolded_title . ' <span>' . $prev_post_subtext . '</span>';
    } else {
        $title = $prev_post_title;
    }
    echo '<a rel="prev" class="post_nav prev_post" href="' . $prev_post_link . '" title="' . $prev_post_title . '">' . $title . '</a>';
}
?>
<?php
$next_post = get_next_post($format, $link, $in_same_term = true, $excluded_terms = '', $taxonomy = 'webinar_type');
if (!empty( $next_post )) {
    $next_post_ID = $next_post->ID;
    $next_post_link = get_permalink($next_post_ID);
    $next_post_title = get_the_title($next_post_ID);
    $next_post_bolded_title = get_field('bolded_title', $next_post_ID);
    $next_post_subtext = get_field('subtext', $next_post_ID);
    if($next_post_bolded_title || $next_post_subtext ) {
        $title = $next_post_bolded_title . ' <span>' . $next_post_subtext . '</span>';
    } else {
        $title = $next_post_title;
    }
    echo '<a rel="next" class="post_nav next_post" href="' . $next_post_link . '" title="' . $next_post_title . '">' . $title . '</a>';
}
?>

If I remove

$format, $link, $in_same_term = true, $excluded_terms = '', $taxonomy = 'webinar_type'

from one, then the other works and vice versa, but never both.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.