[Resolved] Limit custom post navigation to current taxonomy

Home Forums Support [Resolved] Limit custom post navigation to current taxonomy

Home Forums Support Limit custom post navigation to current taxonomy

Viewing 9 posts - 1 through 9 (of 9 total)
  • Author
    Posts
  • #1038110
    ic7

    Hi,

    I’m using GeneratePress & GP Premium.
    I would like to limit the post navigation of a custom post type to the current posts custom taxonomy.
    Is that possible?

    Thanks for your help in advance!

    Best regards,
    Sebastian

    #1038555
    Tom
    Lead Developer
    Lead Developer

    Hi there,

    Give this a shot:

    add_filter( 'generate_category_post_navigation', '__return_true' );

    Let me know πŸ™‚

    #1038724
    ic7

    Hi Tom,

    I should have mentioned, I’m using this code to generate the custom post type navigation:

    add_action( 'generate_after_entry_content', 'tu_cpt_footer_meta' );
    function tu_cpt_footer_meta()
    {
    	if ( 'post' == get_post_type() || 'projekte' == get_post_type() ) : ?>
    		<footer class="entry-meta">
    			<?php generate_entry_meta(); ?>
    			<?php if ( is_single() ) generate_content_nav( 'nav-below' ); ?>
    		</footer><!-- .entry-meta -->
    	<?php endif;
    }

    The above filter results in no output.

    #1039085
    Tom
    Lead Developer
    Lead Developer

    It seems like we need to add another parameter here to include the taxonomy: https://github.com/tomusborne/generatepress/blob/2.3.2/inc/structure/post-meta.php#L53

    This has come up a couple of times, so I’m going to add a new filter in GP 2.4. I’ll update this topic once I commit the change so you can make the change on your installation πŸ™‚

    #1041590
    Tom
    Lead Developer
    Lead Developer

    Hi there,

    I’ve added a new filter in GP 2.4: https://github.com/tomusborne/generatepress/commit/4b1c9275f87fb340144dd4ae3037848fcc9c93a8

    This will allow you to do this:

    add_filter( 'generate_post_navigation_args', function( $args ) {
        $args['taxonomy'] = 'your-custom-taxonomy';
    
        return $args;
    } );
    #1063657
    ic7

    Hi Tom,

    thanks for adding this new filter to the new version!
    I couldn’t get the desired output with the 2.4-beta1, but I’m sure I missed something.

    The custom post type is called ‘projekte’, with a custom taxonomy called ‘bereiche’.
    This taxonomy has different terms added, let’s call them ‘term-1’, ‘term-2’, ‘term-3’, …
    Now if a user views a single post added to ‘term-1’, I want the post navigation to only display links to posts added the same term.

    Is this possible with the new filter?

    Here’s the code I’m currently working with, but it’s missing the term limitation:

    add_action( 'generate_after_entry_content', 'tu_cpt_footer_meta' );
    function tu_cpt_footer_meta()
    {
    	if ( 'post' == get_post_type() || 'projekte' == get_post_type() ) : ?>
    		<footer class="entry-meta">
    			<?php generate_entry_meta(); ?>
    			<?php if ( is_single() ) generate_content_nav( 'nav-below' ); ?>
    		</footer><!-- .entry-meta -->
    	<?php endif;
    }
    
    add_filter( 'generate_post_navigation_args', function( $args ) {
        $args['taxonomy'] = 'bereiche';
        return $args;
    } );

    Thanks for your help in advance!

    #1064139
    Tom
    Lead Developer
    Lead Developer

    Hi there,

    Try this:

    add_filter( 'generate_post_navigation_args', function( $args ) {
        if ( 'projekte' == get_post_type() ) {
            $args['in_same_term'] = true;
            $args['taxonomy'] = 'bereiche';
        }
    
        return $args;
    } );

    Let me know πŸ™‚

    #1064168
    ic7

    This works perfectly, Tom!
    Thank you very much!

    #1064527
    Tom
    Lead Developer
    Lead Developer

    Awesome! No problem πŸ™‚

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