- This topic has 5 replies, 2 voices, and was last updated 6 years, 4 months ago by
Tom.
-
AuthorPosts
-
December 4, 2019 at 6:30 am #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
December 4, 2019 at 6:27 pm #1093888Tom
Lead DeveloperLead DeveloperHi 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 🙂
December 5, 2019 at 12:59 am #1094160alexis
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 translatorDecember 5, 2019 at 9:34 am #1094825Tom
Lead DeveloperLead DeveloperYou 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 ); } }December 5, 2019 at 9:51 am #1094862alexis
Perfect! thanks for your help (because it’s wordpress and not your theme)
December 5, 2019 at 10:10 am #1094883Tom
Lead DeveloperLead DeveloperNo problem! 🙂
-
AuthorPosts
- You must be logged in to reply to this topic.