WordPress.org

Ready to get started?Download WordPress

Forums

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

  1. hilj
    Member
    Posted 9 months ago #

    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/

  2. hilj
    Member
    Posted 9 months 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
    Member
    Plugin Author

    Posted 8 months ago #

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

Reply

You must log in to post.

About this Plugin

About this Topic

Tags

No tags yet.