Next Post Link
Being used mainly on single post template, this tag display a link to a next post relative to the current post, from a sort list.
This tag must be used within the query loop.
The default WordPress function used for next navigational link is next_post_link. This is very limited in functionality and there is no possibility to apply a sort list and a specific taxonomy term to which the post is related to.
An improvement for that function is next_post_type_link
Arguments:
next_post_type_link($format, $link, $argv);
If $argv is empty the archive order will be used.
Parameters
$format
(string) Format string for the link. This is where to control what comes before and after the link. ‘%link’ in the 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’.
$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 apply
taxonomy – use a specified sort taxonomy
term_id – use a specified sort taxonomy term
Examples
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 );
Using WPML return next post link using order from taxonomy ‘Features’ within term_id 10
$args = array( 'sort_id' => 25, 'taxonomy' => 'features', 'term_id' => apply_filters( 'wpml_object_id', 10, 'category', TRUE ) ); next_post_type_link( '%link', __( '<span class="meta-nav">Next Post</span> %title', 'twentyfourteen' ), $args );
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.
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.
[…] function format has been deprecated, see this post instead Next Post Link for v3 […]
looking for a good approach when using
Next/Previous Post Link Plus
was using this: true, ‘link’ => ‘Next Leader’ ) ); ?>
Can you check with above function and examples? Also check with https://www.nsp-code.com/advanced-post-types-order-api/previous-post-link/
If you meant something else, please send additional description. Make sure you use the contact form for a fast support.
Which page should i write this cod? each post page? Can i set each category? (My post included in only 1 category)
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.
Can someone please explain me what is “sort_id”?
Thanks!
Hi
Within admin sort page, there’s the first metabox titled Sort List Settings ( ID XX ). What’s XX is what you looking for.
Thanks
Thanks for a quick reply.
Can I get that sort_id inside template in case I know taxonomy and term?
Hi,
See this article at https://www.nsp-code.com/retrieve-programmatically-the-sort_id-and-sort_view_id-by-specified-arguments/
Thanks
I get this message if I try to use this code:
Notice: Undefined property: stdClass::$relation in /home/andrewtest/public_html/wp-content/plugins/advanced-post-types-order/include/apto_functions-class.php on line 669