From 6f7880bcf476068fa31405d1132c1095743bcfc2 Mon Sep 17 00:00:00 2001 From: Boone Gorges Date: Thu, 6 Nov 2014 20:11:34 +0000 Subject: [PATCH] In `get_adjacent_post()`, `$excluded_terms` should check term_id rather than term_taxonom_id. See #29663, #22112. git-svn-id: https://develop.svn.wordpress.org/trunk@30263 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/link-template.php | 2 +- tests/phpunit/tests/link.php | 13 ++++++++++--- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/src/wp-includes/link-template.php b/src/wp-includes/link-template.php index 8d6830ca5f..c603eddbd5 100644 --- a/src/wp-includes/link-template.php +++ b/src/wp-includes/link-template.php @@ -1513,7 +1513,7 @@ function get_adjacent_post( $in_same_term = false, $excluded_terms = '', $previo } if ( ! empty( $excluded_terms ) ) { - $where .= " AND p.ID NOT IN ( SELECT object_id FROM $wpdb->term_relationships WHERE term_taxonomy_id IN (" . implode( $excluded_terms, ',' ) . ') )'; + $where .= " AND p.ID NOT IN ( SELECT tr.object_id FROM $wpdb->term_relationships tr LEFT JOIN $wpdb->term_taxonomy tt ON (tr.term_taxonomy_id = tt.term_taxonomy_id) WHERE tt.term_id IN (" . implode( $excluded_terms, ',' ) . ') )'; } } diff --git a/tests/phpunit/tests/link.php b/tests/phpunit/tests/link.php index 88816faa14..9e3a39d1a0 100644 --- a/tests/phpunit/tests/link.php +++ b/tests/phpunit/tests/link.php @@ -190,10 +190,17 @@ class Tests_Link extends WP_UnitTestCase { } /** - * @ticket 22112 - */ + * @ticket 22112 + */ function test_get_adjacent_post_exclude_self_term() { - $include = $this->factory->category->create(); + // Bump term_taxonomy to mimic shared term offsets. + global $wpdb; + $wpdb->insert( $wpdb->term_taxonomy, array( 'taxonomy' => 'foo', 'term_id' => 12345 ) ); + + $include = $this->factory->term->create( array( + 'taxonomy' => 'category', + 'name' => 'Include', + ) ); $exclude = $this->factory->category->create(); $one = $this->factory->post->create_and_get( array(