[Resolved] Limit Post Navigation to Category

Home Forums Support [Resolved] Limit Post Navigation to Category

Home Forums Support Limit Post Navigation to Category

Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #624458
    JANEK

    Good morning,

    I just noticed that the post navigation that appears on single posts is not limited to the the posts category so will pick up everything. Is there a way to limit the post navigation to their respective category? Or will it be a case of just having to tell the post navigation to exclude certain categories I dont want displayed?

    #624532
    Tom
    Lead Developer
    Lead Developer

    There’s a filter for that!

    add_filter( 'generate_category_post_navigation', '__return_true' );

    That should do it πŸ™‚

    #624538
    JANEK

    Awesome, is there a way to make this function only on the Post type. Rather than everything. I have a custom post type that I’d like to retain the original functionality on, but on my default Post type I just want it to navigate its respective categories.

    #625008
    Tom
    Lead Developer
    Lead Developer

    You could try:

    add_action( 'wp', 'tu_cpt_cat_specific_links' );
    function tu_cpt_cat_specific_links() {
        if ( is_singular( 'your-post-type' ) ) {
            add_filter( 'generate_category_post_navigation', '__return_true' );
        }
    }
    #625230
    JANEK

    Done and dusted! That was easy. Thank you! πŸ™‚

    #625311
    Tom
    Lead Developer
    Lead Developer

    You’re welcome πŸ™‚

    #635713
    JANEK

    Hey Tom,

    Sorry to dredge this one up, it seems to not work on custom post types. For example I’m using the Seriously Simple Podcast plugin and its added a custom post type named ‘podcast’ to the site. However I dont think the podcast CPT uses the name categories which your code refers to but rather it uses a custom taxonomy which they’ve called ‘series’. Would you be able to assist me in modifying your code to work with the new taxonomy and CPT name?

    To give you an idea of what I’m trying to achieve… I have two series (categories) one is the main podcast series the other is titled next episode, and I want to keep the next episode out of the post navigation essentially. If that makes sense.

    Your login is still valid for the site if you want to take a look at how the podcast series are setup.

    The site url is:
    http://staging.janek-dev.flywheelsites.com/

    #636253
    Tom
    Lead Developer
    Lead Developer

    Yea, the taxonomy being different will mess it up.

    I’m not 100% sure, but you could try this:

    add_filter( 'get_next_post_join', 'tu_adjust_taxonomy_links' );
    add_filter( 'get_previous_post_join', 'tu_adjust_taxonomy_links' );
    function tu_adjust_taxonomy_links( $join, $in_same_term, $excluded_terms, $taxonomy ) {
        if ( ! is_singular( 'podcast' ) ) {
            return $join;
        }
    
        $taxonomy = 'series';
    
        return $join;
    }
Viewing 8 posts - 1 through 8 (of 8 total)
  • You must be logged in to reply to this topic.