Next Post Link

Share on FacebookTweet about this on TwitterShare on Google+Share on LinkedInPrint this page

Used on single post permalink pages, this template tag displays a link to the next post which exists in chronological order from the current post.

This tag must be used in The Loop.

The default WordPress function for this is next_post_link. However this is a very limited procedure and there is no way to receive the next post within a taxonomy term and using the custom defined order.

An improvement for that function is next_post_type_link

next_post_type_link($format, $link, $argv);

If $argv is empty the archive order will be used.

(string) Format string for the link. This is where to control what comes before and after the link. ‘%link’ in string will be replaced with whatever is declared as ‘link’ (see next parameter). ‘Go to %link’ will generate “Go to <a href=…” Put HTML tags here to style the final results. Defaults to ‘« %link’.

(string) Link text to display. Defaults to next post’s title (‘%title’).

$argv(array) List of function arguments:
sort_id – the sort id which order will be used
taxonomy – use the specified sort taxonomy
term_id – use the specified sort taxonomy term


Return next post link using order from taxonomy ‘Features’ within term_id 10

$args   =   array(
                        'sort_id'   =>  25,
                            'taxonomy'  =>  'features',
                            'term_id'   =>  10
next_post_type_link( '%link', __( '<span class="meta-nav">Next Post</span> %title', 'twentyfourteen' ), $args );

Usign WPML return next post link using order from taxonomy ‘Features’ within term_id 10

$args   =   array(
                        'sort_id'   =>  25,
                            'taxonomy'  =>  'features',
                            'term_id'   =>  icl_object_id(10 , 'features')
next_post_type_link( '%link', __( '<span class="meta-nav">Next Post</span> %title', 'twentyfourteen' ), $args );
API Index

  • Kristin Jobin

    How do I do this with multiple categories other than using the archive?

  • you have to use conditionals. for having to pay $25, its ridiculous.

    • nspcode

      Sorry but this is only an Advanced Post Types Order plugin feature.

  • I actually set the first term id ( since it was restricted to one term ) to a variable, which I just put into the line. Works surprisingly nice.

  • Pingback: Next Post Link – V2 Series | Nsp Code()

  • John

    looking for a good approach when using
    Next/Previous Post Link Plus
    was using this: true, ‘link’ => ‘Next Leader’ ) ); ?>

  • K.Uchi

    Which page should i write this cod? each post page? Can i set each category? (My post included in only 1 category)

    • nspcode

      You should place the code within theme template file where use the navigational links.
      You can set a category (term_id) see the code example on this page.

  • Milenko R

    Can someone please explain me what is “sort_id”?

    • nspcode

      Within admin sort page, there’s the first metabox titled Sort List Settings ( ID XX ). What’s XX is what you looking for.