Ready to get started?Download WordPress


[resolved] Append a variable to next_post_link URL (5 posts)

  1. traumm
    Posted 3 years ago #

    Is there any way of appending a variable onto the URL generated by the next_post_link function?

    next_post_link('%link', 'Next', FALSE, '1');

    As is stands, this would link to, for example:


    When I need it to link to:


    from certain pages.

    Any help appreciated!

  2. keesiemeijer
    Posted 3 years ago #

    I dont think you can do it with next_post_link. try it with get_adjacent_post.
    something like this:

    $next_post = get_adjacent_post( false, '', false );
    $previous_post = get_adjacent_post( false, '', true );
    if($previous_post) : ?>
    <a href="<?php echo get_permalink($previous_post->ID); ?>?new=1"><?php echo get_the_title($previous_post->ID) ?></a>
    <?php php endif; ?>
    <?php if($next_post) : ?>
    <a href="<?php echo get_permalink($next_post->ID); ?>?new=1"><?php echo get_the_title($next_post->ID) ?></a>
    <?php php endif; ?>
  3. Brad Markle
    Posted 3 years ago #

    Hi traumm, instead of next_post_link, have you tried the get_next_posts_link function? I believe this is a similar thread:

    [resolved] Next and Previous Posts URLs

  4. keesiemeijer
    Posted 3 years ago #

    Even better imh_brad!

  5. traumm
    Posted 3 years ago #

    I ended up get_adjacent_post in the end - it's working fine now!

    Thanks both!

Topic Closed

This topic has been closed to new replies.

About this Topic