functions - Previous_post and Next_post - Custom Post Type

I have a custom post type and using this function to add for posts, previous and next buttons. The problem is that withi

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', '&#8606;', FALSE); ?>
        </div>
        <div class="arrowRight">
            <?php next_post_link('%link', '&#8608;', 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', '&#8606;', FALSE); ?>
        </div>
        <div class="arrowRight">
            <?php next_post_link('%link', '&#8608;', 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
Add a comment  | 

2 Answers 2

Reset to default 1

You 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', '&#8606;', TRUE); ?>
        </div>
        <div class="arrowRight">
            <?php next_post_link('%link', '&#8608;', 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

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744744100a4591204.html

相关推荐

  • functions - Previous_post and Next_post - Custom Post Type

    I have a custom post type and using this function to add for posts, previous and next buttons. The problem is that withi

    18小时前
    40

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信