I have a custom post type and using this function to add for posts, previous and next buttons.
The problem is that within the custom post type, I have subcategories defined by a custom field category
.
Is there a way to limit the previous and next post link for items only within the same category of the current post?
function crunchify_post_navigation(){
?>
<div class="arrowNav">
<div class="arrowLeft">
<?php previous_post_link('%link', '↞', FALSE); ?>
</div>
<div class="arrowRight">
<?php next_post_link('%link', '↠', FALSE); ?>
</div>
</div>
<?php
}
add_action('wp_footer', 'crunchify_post_navigation');
I have a custom post type and using this function to add for posts, previous and next buttons.
The problem is that within the custom post type, I have subcategories defined by a custom field category
.
Is there a way to limit the previous and next post link for items only within the same category of the current post?
function crunchify_post_navigation(){
?>
<div class="arrowNav">
<div class="arrowLeft">
<?php previous_post_link('%link', '↞', FALSE); ?>
</div>
<div class="arrowRight">
<?php next_post_link('%link', '↠', FALSE); ?>
</div>
</div>
<?php
}
add_action('wp_footer', 'crunchify_post_navigation');
Share
Improve this question
asked Mar 1, 2017 at 14:21
JoaMikaJoaMika
6986 gold badges27 silver badges58 bronze badges
2 Answers
Reset to default 1You want to change the in_same_term
value to TRUE as follows:
function crunchify_post_navigation(){
?>
<div class="arrowNav">
<div class="arrowLeft">
<?php previous_post_link('%link', '↞', TRUE); ?>
</div>
<div class="arrowRight">
<?php next_post_link('%link', '↠', TRUE); ?>
</div>
</div>
<?php
}
add_action('wp_footer', 'crunchify_post_navigation');
This function must be used within the loop.
https://codex.wordpress/Function_Reference/next_post_link