Site logo

Archived topic

do not display the next or previous articles: categories id

5 replies · Started by alexis on December 4, 2019

Viewing posts 1–6 of 6

I want items with the id'4' not to display items with the id'5'.
I found this function that is already in place :

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( 4 );
}

But here I want to put if (articles with id' 4') {

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( 5 );
}`

}

Sorry, I can't find the solution after several ho`urs of search

Hi there,

Just to confirm, are you wanting to exclude a term from showing up (4) if the current post has another term (5)?

Let me know :)

To be more precise and to have a cleaner code I actually think it would have to be something like that:

if (in article with category id 4) {

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( 5 );
}

}
else if (in article with category id 5){

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( 4 );
}

}
Sorry I'm a young French wordpress developer, I hope what I write is understandable because I use a translator

You could try this:

add_filter( 'get_next_post_excluded_terms', 'tu_exclude_terms' );
add_filter( 'get_previous_post_excluded_terms', 'tu_exclude_terms' );

function tu_exclude_terms() {
    if ( has_category( 4 ) ) {
        return array( 5 );
    } elseif ( has_category( 5 ) ) {
        return array( 4 );
    }
}

Perfect! thanks for your help (because it's wordpress and not your theme)

No problem! :)

This archived topic is closed to new replies.