• Resolved anjanphukan

    (@anjanphukan)


    Hi

    Is there a way to show post navigation with the same taxonomy for custom post type?

    I tried the following code but it works only for Posts and not for CPTs.

    <?php 
    function previous_posts_from_same_category( $args ) {
    $args['in_same_term'] = true;
    return $args;
    }
    add_filter( 'astra_single_post_navigation', 'previous_posts_from_same_category' );
Viewing 3 replies - 1 through 3 (of 3 total)
  • Hi @anjanphukan,

    You can try adding the following code to your site:

    <?php
    function previous_posts_from_same_taxonomy_cpt( $args ) {
        if ( get_post_type() === 'your_custom_post_type' ) { // Specify your CPT here
            $args['in_same_term'] = true;
            $args['taxonomy'] = 'your_taxonomy'; // Specify the taxonomy name here
        }
        return $args;
    }
    
    add_filter( 'astra_single_post_navigation', 'previous_posts_from_same_taxonomy_cpt' );

    If this doesn’t resolve the issue, it may require additional customization. I’d suggest reaching out to the CPT plugin support team, who would have more specific resources to assist.

    Kind regards,
    Aradhy ??

    Thread Starter anjanphukan

    (@anjanphukan)

    Hi @bsfaradhy

    This is exactly what I wanted. It works for me. Thank you so much.

    Hi @anjanphukan,

    Happy to help!

    If you’re happy with the support and product, feel free to share your experience by leaving a rating or review on our reviews page. It really helps us improve and continue providing great support!

Viewing 3 replies - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.