Site logo

Archived topic

Limit custom post navigation to current taxonomy

8 replies · Started by ic7 on October 18, 2019

Viewing posts 1–9 of 9

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

Hi there,

Give this a shot:

add_filter( 'generate_category_post_navigation', '__return_true' );

Let me know :)

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.

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!

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 :)

This works perfectly, Tom!
Thank you very much!

Awesome! No problem :)

This archived topic is closed to new replies.