Make WordPress Core


Ignore:
Timestamp:
09/21/2022 05:27:12 AM (4 years ago)
Author:
peterwilsoncc
Message:

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/post.php

    r54267 r54271  
    57765776function get_page_by_title( $page_title, $output = OBJECT, $post_type = 'page' ) {
    57775777        $args  = array(
    5778                 'post_title'             => $page_title,
     5778                'title'                  => $page_title,
    57795779                'post_type'              => $post_type,
    57805780                'post_status'            => get_post_stati(),
    … …  
    57835783                'update_post_meta_cache' => false,
    57845784                'no_found_rows'          => true,
    5785                 'orderby'                => 'ID',
     5785                'orderby'                => 'post_date ID',
    57865786                'order'                  => 'ASC',
    57875787        );
Note: See TracChangeset for help on using the changeset viewer.