Changeset 37712
- Timestamp:
- 06/15/2016 12:32:25 PM (8 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/query.php
r37692 r37712 3651 3651 } 3652 3652 3653 // Convert to WP_Post objects and set the found-post totals. 3653 $this->set_found_posts( $q, $limits ); 3654 3655 // Convert to WP_Post objects. 3654 3656 if ( $this->posts ) { 3655 3657 $this->posts = array_map( 'get_post', $this->posts ); 3656 $this->set_found_posts( $q, $limits );3657 3658 } 3658 3659 -
trunk/tests/phpunit/tests/post/query.php
r37692 r37712 413 413 return array( 12345 ); 414 414 } 415 416 /** 417 * @ticket 36687 418 */ 419 public function test_posts_pre_query_filter_should_respect_set_found_posts() { 420 global $wpdb; 421 422 $this->post_id = self::factory()->post->create(); 423 424 // Prevent the DB query 425 add_filter( 'posts_request', '__return_empty_string' ); 426 add_filter( 'found_posts_query', '__return_empty_string' ); 427 428 // Add the post and found_posts 429 add_filter( 'the_posts', array( $this, 'filter_the_posts' ) ); 430 add_filter( 'found_posts', array( $this, 'filter_found_posts' ) ); 431 432 $q = new WP_Query( array( 'suppress_filters' => false ) ); 433 434 remove_filter( 'posts_request', '__return_empty_string' ); 435 remove_filter( 'found_posts_query', '__return_empty_string' ); 436 remove_filter( 'the_posts', array( $this, 'filter_the_posts' ) ); 437 remove_filter( 'found_posts', array( $this, 'filter_found_posts' ) ); 438 439 $this->assertSame( array( $this->post_id ), wp_list_pluck( $q->posts, 'ID' ) ); 440 $this->assertSame( 1, $q->found_posts ); 441 } 442 443 public function filter_the_posts() { 444 return array( get_post( $this->post_id ) ); 445 } 446 447 public function filter_found_posts( $posts ) { 448 return 1; 449 } 415 450 }
Note: See TracChangeset
for help on using the changeset viewer.