WP_Query Powered Adjacent Post Link
Next returns ID to itself where it should return nothing (3 posts)

  1. hilj
    Posted 2 years ago #

    I have a thing like this:

    <nav class="prev-next margin-t-20 float-left">
        $args = array(
            'post_type' => 'work',
            'orderby'   => 'menu_order'
        $prev_post = wpqpapl($post->ID, $args, 'previous', 'ID');
        $next_post = wpqpapl($post->ID, $args, 'next', 'ID');
        <div class="next-link margin-r-20 dehighlight">
            <?php if ( !empty( $next_post ) ) { ?>
                <a id="next-link" href="<?php echo get_permalink( $next_post ); ?>">&larr;</a>
            <?php } else { ?>
            <?php } ?>
        <div class="prev-link dehighlight">
            <?php if ( !empty( $prev_post ) ) { ?>
                <a id="prev-link" href="<?php echo get_permalink( $prev_post ); ?>">&rarr;</a>
            <?php } else { ?>
            <?php } ?>

    I check if $next_page and $prev_page have something in them and display an arraow (← or → ) inside a link to a next post.

    When it gets to the last post, the previous returns nothing, like it should, cause there is no previous posts. But when it gets to the first post, the next returns the current page.

    Is it just me or a bug? (probably just me)


  2. hilj
    Posted 2 years ago #

    Alrite, it's solvable of course like this

    if ( empty( $next_post ) || $next_post === $post->ID ) {
         // Don't show next link
    } else {
        // Show next link
  3. Ryan Burnette
    Plugin Author

    Posted 2 years ago #

    That sounds like a bug to me. I'll take a look when I work on this plugin again.

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic


No tags yet.