Opened 10 years ago
Last modified 5 weeks ago
#40660 new defect (bug)
the_post_navigation not excluding terms - wp 4.7.4
| Reported by: | Sbaxter_Quba | Owned by: | |
|---|---|---|---|
| Priority: | normal | Milestone: | Awaiting Review |
| Component: | Query | Version: | 4.7.4 |
| Severity: | normal | Keywords: | close |
| Cc: | Focuses: |
Description
I'm retrieving the post navigation as so
<?php $args = array( 'in_same_term' => true, 'excluded_terms' => '129', 'taxonomy' => 'category' ); the_post_navigation( $args )
I've debugged and it constructs the $where clause here as it should (properly excluding the term) https://github.com/WordPress/WordPress/blob/master/wp-includes/link-template.php#L1647
$where = AND tt.taxonomy = 'category' AND tt.term_id IN (127) AND p.ID NOT IN ( SELECT tr.object_id FROM wp_term_relationships tr LEFT JOIN wp_term_taxonomy tt ON (tr.term_taxonomy_id = tt.term_taxonomy_id) WHERE tt.term_id IN (129) ) AND ( p.post_status = 'publish' OR p.post_status = 'private' )
This is then replaced here https://github.com/WordPress/WordPress/blob/master/wp-includes/link-template.php#L1716 it improperly constructs the where clause so that the result is as follows
$where = WHERE p.menu_order > '2' AND p.post_type = 'post' AND p.post_status = 'publish'
This means i cannot excluded other categories from the post navigation or specify which categories to exclude.
Change History (3)
Note:
See TracTickets
for help on using tickets.
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)
Reproduction Report
I investigated and tested this ticket on WordPress Trunk (
7.2-alpha-63166-src) to verify whetherexcluded_termsproperly excludes terms in adjacent post queries.Environment
Test Scenario
Normal CategoryandExcluded Category.get_adjacent_post()andthe_post_navigation():Results
get_adjacent_post()without exclusions correctly returned Post 2.get_adjacent_post()withexcluded_termscorrectly skipped Post 2 and returned Post 1.the_post_navigation()rendered navigation pointing to Post 1, successfully excluding Post 2.Analysis
In the ticket description, the reported
$whereclause was:WHERE p.menu_order > '2' AND p.post_type = 'post' AND p.post_status = 'publish'WordPress Core's
get_adjacent_post()operates strictly onp.post_dateand does not usep.menu_orderin adjacent post queries. The query mentioned in the report indicates that a custom theme or third-party plugin hooked into theget_{$adjacent}_post_wherefilter and completely overwrote$where, stripping Core's category exclusion query.Conclusion & Recommendation
On a stock WordPress installation,
the_post_navigation()andget_adjacent_post()correctly exclude the specified terms. Since Core behaves as expected and the issue was caused by an external filter overriding the query, I recommend closing this ticket asinvalidorworksforme.Removing
needs-testingand addingclosefor maintainer review.