Posts, Post Types: Fix WP_Query parameter used by get_page_by_title().

Fixes the call to `WP_Query` within `get_page_by_title()` by using the correct title parameter, `title`.

Modify the `orderby` parameter to prioritize the oldest published date over the smallest post ID. This ensures the behaviour matches that of the previous version of `get_page_by_title()`.

The tests have been modified to include a populated post table to ensure the posts returned are matched by design rather than coincidence.

Follow up to [54234].

Props dd32, timothyblynjacobs, peterwilsoncc.
Fixes #56609.
See #36905.



git-svn-id: https://develop.svn.wordpress.org/trunk@54271 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Peter Wilson
2022-09-21 05:27:12 +00:00
parent 77e65eace5
commit 6c6a6747a0
2 changed files with 84 additions and 2 deletions

View File

@@ -5775,14 +5775,14 @@ function get_page_by_path( $page_path, $output = OBJECT, $post_type = 'page' ) {
*/
function get_page_by_title( $page_title, $output = OBJECT, $post_type = 'page' ) {
$args = array(
'post_title' => $page_title,
'title' => $page_title,
'post_type' => $post_type,
'post_status' => get_post_stati(),
'posts_per_page' => 1,
'update_post_term_cache' => false,
'update_post_meta_cache' => false,
'no_found_rows' => true,
'orderby' => 'ID',
'orderby' => 'post_date ID',
'order' => 'ASC',
);
$query = new WP_Query( $args );