Changeset 36078
- Timestamp:
- 12/23/2015 07:56:32 PM (9 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/link-template.php
r36011 r36078 1569 1569 $join = ''; 1570 1570 $where = ''; 1571 $adjacent = $previous ? 'previous' : 'next'; 1571 1572 1572 1573 if ( $in_same_term || ! empty( $excluded_terms ) ) { … … 1600 1601 $where .= " AND tt.term_id IN (" . implode( ',', $term_array ) . ")"; 1601 1602 } 1603 1604 /** 1605 * Filter the IDs of terms excluded from adjacent post queries. 1606 * 1607 * The dynamic portion of the hook name, `$adjacent`, refers to the type 1608 * of adjacency, 'next' or 'previous'. 1609 * 1610 * @since 4.4.0 1611 * 1612 * @param string $excluded_terms Array of excluded term IDs. 1613 */ 1614 $excluded_terms = apply_filters( "get_{$adjacent}_post_excluded_terms", $excluded_terms ); 1602 1615 1603 1616 if ( ! empty( $excluded_terms ) ) { … … 1636 1649 } 1637 1650 1638 $adjacent = $previous ? 'previous' : 'next';1639 1651 $op = $previous ? '<' : '>'; 1640 1652 $order = $previous ? 'DESC' : 'ASC'; 1641 1642 /**1643 * Filter the excluded term ids1644 *1645 * The dynamic portion of the hook name, `$adjacent`, refers to the type1646 * of adjacency, 'next' or 'previous'.1647 *1648 * @since 4.4.01649 *1650 * @param string $excluded_terms Array of excluded term IDs.1651 */1652 $excluded_terms = apply_filters( "get_{$adjacent}_post_excluded_terms", $excluded_terms );1653 1653 1654 1654 /** -
trunk/tests/phpunit/tests/link/getAdjacentPost.php
r36077 r36078 5 5 */ 6 6 class Tests_Link_GetAdjacentPost extends WP_UnitTestCase { 7 protected $exclude_term; 8 7 9 /** 8 10 * @ticket 17807 … … 211 213 $this->assertEquals( $p3, $found->ID ); 212 214 } 215 216 /** 217 * @ticket 35211 218 */ 219 public function test_excluded_terms_filter() { 220 register_taxonomy( 'wptests_tax', 'post' ); 221 222 $terms = self::factory()->term->create_many( 2, array( 223 'taxonomy' => 'wptests_tax', 224 ) ); 225 226 $p1 = self::factory()->post->create( array( 'post_date' => '2015-08-27 12:00:00' ) ); 227 $p2 = self::factory()->post->create( array( 'post_date' => '2015-08-26 12:00:00' ) ); 228 $p3 = self::factory()->post->create( array( 'post_date' => '2015-08-25 12:00:00' ) ); 229 230 wp_set_post_terms( $p1, array( $terms[0], $terms[1] ), 'wptests_tax' ); 231 wp_set_post_terms( $p2, array( $terms[1] ), 'wptests_tax' ); 232 wp_set_post_terms( $p3, array( $terms[0] ), 'wptests_tax' ); 233 234 $this->go_to( get_permalink( $p1 ) ); 235 236 $this->exclude_term = $terms[1]; 237 add_filter( 'get_previous_post_excluded_terms', array( $this, 'filter_excluded_terms' ) ); 238 239 $found = get_adjacent_post( true, array(), true, 'wptests_tax' ); 240 241 remove_filter( 'get_previous_post_excluded_terms', array( $this, 'filter_excluded_terms' ) ); 242 unset( $this->exclude_term ); 243 244 $this->assertSame( $p3, $found->ID ); 245 } 246 247 public function filter_excluded_terms( $excluded_terms ) { 248 $excluded_terms[] = $this->exclude_term; 249 return $excluded_terms; 250 } 213 251 }
Note: See TracChangeset
for help on using the changeset viewer.