[Resolved] do not display the next or previous articles: categories id

Home Forums Support do not display the next or previous articles: categories id

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #1093046
    alexis

    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

    Alexis
    agency K-LYA

    #1093888
    Tom
    Lead Developer
    Lead Developer

    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 🙂

    #1094160
    alexis

    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

    Alexis
    agency K-LYA

    #1094825
    Tom
    Lead Developer
    Lead Developer

    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 );
        }
    }
    #1094862
    alexis

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

    Alexis
    agency K-LYA

    #1094883
    Tom
    Lead Developer
    Lead Developer
Viewing 6 posts - 1 through 6 (of 6 total)
  • You must be logged in to reply to this topic.