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