Posts, Post Types: Avoid redundant SQL query in get_pages().

This avoids an additional query by passing the query args directly to the `WP_Query::query()` method, rather than to the constructor and calling get_posts(), following [55569].

Props david.binda, azaozz, spacedmonkey, mukesh27, flixos90, SergeyBiryukov, joemcgill.
Fixes #59224.


git-svn-id: https://develop.svn.wordpress.org/trunk@56491 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Joe McGill 2023-08-29 22:11:22 +00:00
parent 3d2f4d5a88
commit e278fe3fcf

View File

@ -6105,8 +6105,8 @@ function get_pages( $args = array() ) {
*/
$query_args = apply_filters( 'get_pages_query_args', $query_args, $parsed_args );
$query = new WP_Query( $query_args );
$pages = $query->get_posts();
$pages = new WP_Query();
$pages = $pages->query( $query_args );
if ( $child_of || $hierarchical ) {
$pages = get_page_children( $child_of, $pages );