Make WordPress Core


Ignore:
Timestamp:
01/14/2022 05:50:52 PM (4 years ago)
Author:
SergeyBiryukov
Message:

Tests: Avoid duplicate queries in some WP_Query tests.

When passing args to the WP_Query::__construct() method, it internally executes the WP_Query::get_posts() method and stores the result in the WP_Query::posts property.

When calling WP_Query::get_posts() again, the same SQL query gets executed, and the result is again stored in the WP_Query::posts property.

Thus, the correct usage is to read the posts already stored in the WP_Query::posts property.

Follow-up to [1062/tests], [1065/tests], [1066/tests], [1070/tests], [29805], [31286], [49900], [51144].

Props david.binda.
Fixes #54822.

File:
1 edited

Legend:

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

    r52389 r52577  
    10251025        );
    10261026
    1027         $posts = $query->get_posts();
    1028         $this->assertCount( 0, $posts );
     1027        $this->assertCount( 0, $query->posts );
    10291028    }
    10301029
     
    10601059        );
    10611060
    1062         $posts = $query->get_posts();
    1063         $this->assertCount( 0, $posts );
     1061        $this->assertCount( 0, $query->posts );
    10641062    }
    10651063
Note: See TracChangeset for help on using the changeset viewer.