Make WordPress Core


Ignore:
Timestamp:
06/15/2016 12:32:25 PM (9 years ago)
Author:
boonebgorges
Message:

Query: After [37692], don't skip set_found_posts() when no posts are found.

The 'found_posts' filter must continue to run for plugins manipulating post
results via filter.

Props dd32.
Fixes #36687.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/post/query.php

    r37692 r37712  
    413413        return array( 12345 );
    414414    }
     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    }
    415450}
Note: See TracChangeset for help on using the changeset viewer.