WordPress.org

Support

Support » Plugins and Hacks » WP_Query Powered Adjacent Post Link » Next returns ID to itself where it should return nothing

Next returns ID to itself where it should return nothing

  • I have a thing like this:

    <nav class="prev-next margin-t-20 float-left">
        <?php
        $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 { ?>
                &larr;
            <?php } ?>
        </div>
        <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 { ?>
                &rarr;
            <?php } ?>
        </div>
    </nav>

    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)

    http://wordpress.org/plugins/wp-query-powered-adjacent-post-link/

Viewing 2 replies - 1 through 2 (of 2 total)
  • 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
    }
    Plugin Author Ryan Burnette

    @ryanburnette

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

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Next returns ID to itself where it should return nothing’ is closed to new replies.
Skip to toolbar