Site logo

[Support request] Exclude categories from post navigation

Home Forums Support [Support request] Exclude categories from post navigation

Home Forums Support Exclude categories from post navigation

Viewing 10 posts - 1 through 10 (of 10 total)
  • Author
    Posts
  • #2495433
    Bill

    I have core content in a range of topics that I want included in the post navigation. No problem there.

    I have one category that I want excluded from the post navigation.

    I couldn’t see a filter available to do this, so I looked at the underlying theme code. It seemed like I could create a filter hook and then add a code snippet. That didn’t seem to work.

    But it looked like this:

    add_filter( 'generate_post_navigation_exclusion_terms', function() {
        return '13';
    } );

    I’ve also tried this:

    add_filter( 'generate_post_navigation_args', function( $args ) {
        if ( is_single() ) {
    		$args['excluded_terms'] = '13';
        }
        return $args;
    } );

    Each time, I still see a link to the post in that category.

    Is there a simpler and reliable way to achieve the results I’m looking for?

    #2495592
    Bill

    As I look more at this, I am using the Ultimate Category Excluder where I exclude the category from the Front Page.

    The default navigation works properly.

    The post navigation element doesn’t work properly and I wonder if it’s possible there is a bug. In theory, it’s the same query that’s being modified by the plugin.

    #2495619
    Ying
    Staff
    Customer Support
    #2495626
    Bill

    Thanks for the link.

    I write code for a living, so I’m not afraid of coding. But that is too much code to have to add to accomplish this task. I should be able to add a filter (if one doesn’t exist) and then add a function for that filter.

    I should not have to replace entire functions as that solution prescribes. If that function takes on more responsibilities over time or changes its interface, then I will potentially have problems.

    I think generatepress is missing a useful filter and/or has a bug in the post navigation implementation.

    #2495697
    Ying
    Staff
    Customer Support

    I think generatepress is missing a useful filter and/or has a bug in the post navigation implementation.

    There was a WP bug so the below code could not work, can you give it another try?

    add_filter( 'get_next_post_excluded_terms', 'tu_exclude_terms' );
    add_filter( 'get_previous_post_excluded_terms', 'tu_exclude_terms' );
    function tu_exclude_terms() {
        return array( '29' );
    }
    #2505389
    Daniel

    It seems the filter assumes the list of id’s is an array, so you do not have to declare it. This works for me:

    add_filter( ‘get_next_post_excluded_terms’, ‘tu_exclude_terms’ );
    add_filter( ‘get_previous_post_excluded_terms’, ‘tu_exclude_terms’ );
    function tu_exclude_terms() {
    return ‘304,30169’;
    }

    #2561201
    Eva

    Hi, I would like to use this filter too. Can you please explain how I can add it? Should I use the wp_head in the Hooks Element?
    Thank you!
    Eva

    #2561246
    David
    Staff
    Customer Support

    Hi Eva,

    that code is PHP, and it cannot be added to a GP Element.
    This article explains how to add the code:

    https://docs.generatepress.com/article/adding-php/

    #2561287
    Eva

    Thank you, David. I just wanted to be sure and will use the Code Snippets plugin then.

    #2561393
    David
    Staff
    Customer Support

    Glad to be of help!

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