get_next_post term exclusion not working as expected
-
I have posts in a custom post type with a custom taxonomy.
I have 5 total posts, all of which are in term A. 2 of the 5 are in term B. I want to exclude term A from the next and previous post links. I thought it was done like so:
$exclude_ID = 2; // Term 'A' get_previous_post(true, $exclude_ID, 'custom_taxonomy') get_next_post(true, $exclude_ID, 'custom_taxonomy')
What I would expect is it would ignore that the current project belongs to term A and then go to term B and find its sibling in term B. Instead, I’m getting nothing back for either previous or next even though I am certain they are both in term B. So, I’m assuming I have misunderstood how exclusions work or I have something wrong in the code.
If I remove the exclusion, it will get the next/previous posts for term A, no problem.
Any ideas?
Thanks!
Here is the code in question:
$exclude = get_term_by( 'slug', 'featured-projects', 'project_types' ); $exclude_ID = $exclude->term_id; $prev_link = get_previous_post_link('%link', '<i class="fas fa-angle-left"></i>previous project', true, $exclude_ID, 'project_types'); $next_link = get_next_post_link('%link', 'next project<i class="fas fa-angle-right"></i>', true, $exclude_ID, 'project_types'); if (strlen($prev_link)) { echo $prev_link; } if ( strlen($prev_link) && strlen($next_link) ) { echo '<span>|</span>'; } if (strlen($next_link)) { echo $next_link; }
- The topic ‘get_next_post term exclusion not working as expected’ is closed to new replies.