- This topic has 8 replies, 2 voices, and was last updated 6 years, 5 months ago by
Tom.
-
AuthorPosts
-
October 18, 2019 at 7:24 am #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,
SebastianOctober 18, 2019 at 7:36 pm #1038555Tom
Lead DeveloperLead DeveloperHi there,
Give this a shot:
add_filter( 'generate_category_post_navigation', '__return_true' );Let me know 🙂
October 19, 2019 at 2:29 am #1038724ic7
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.
October 19, 2019 at 10:49 am #1039085Tom
Lead DeveloperLead DeveloperIt 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 🙂
October 22, 2019 at 10:07 am #1041590Tom
Lead DeveloperLead DeveloperHi 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; } );November 15, 2019 at 1:01 am #1063657ic7
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!
November 15, 2019 at 8:24 am #1064139Tom
Lead DeveloperLead DeveloperHi 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 🙂
November 15, 2019 at 8:39 am #1064168ic7
This works perfectly, Tom!
Thank you very much!November 15, 2019 at 7:34 pm #1064527Tom
Lead DeveloperLead DeveloperAwesome! No problem 🙂
-
AuthorPosts
- You must be logged in to reply to this topic.