Posts, Post Types: Add a new filter for query arguments in get_pages.

In [55569] `get_pages` was converted to use `WP_Query` internally. But for plugins that were extending the `get_pages` filters and filter `WP_Query` query arguments, this could result in a conflict. Add a filter `get_pages_query_args` to allow developers to change arguments passed to `WP_Query` but also have the context of the original arguments passed to the `get_pages` function. 

This change also expands test coverage of `get_pages` to ensure no breakages in the future. 

Props spacedmonkey, westonruter, costdev, flixos90, kenwins, marianne38.
See #12821.

git-svn-id: https://develop.svn.wordpress.org/trunk@55845 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Jonny Harris
2023-05-22 10:01:07 +00:00
parent 2748b61322
commit 1825c75f88
2 changed files with 194 additions and 1 deletions

View File

@@ -6031,7 +6031,7 @@ function get_pages( $args = array() ) {
}
$post_author = $post_author->ID;
}
$query_args['author__in'][] = $post_author;
$query_args['author__in'][] = (int) $post_author;
}
}
}
@@ -6060,6 +6060,16 @@ function get_pages( $args = array() ) {
$query_args['posts_per_page'] = $number;
}
/**
* Filters query arguments passed to WP_Query in get_pages.
*
* @since 6.3.0
*
* @param array $query_args Array of arguments passed to WP_Query.
* @param array $parsed_args Array of get_pages() arguments.
*/
$query_args = apply_filters( 'get_pages_query_args', $query_args, $parsed_args );
$query = new WP_Query( $query_args );
$pages = $query->get_posts();