[wp-trac] [WordPress Trac] #57041: Deprecate `get_page_by_title()` in favour of `WP_Query`
WordPress Trac
noreply at wordpress.org
Tue Nov 8 23:47:13 UTC 2022
#57041: Deprecate `get_page_by_title()` in favour of `WP_Query`
-------------------------------+--------------------
Reporter: peterwilsoncc | Owner: (none)
Type: enhancement | Status: new
Priority: normal | Milestone: 6.2
Component: Posts, Post Types | Version:
Severity: normal | Keywords:
Focuses: |
-------------------------------+--------------------
As an API `get_page_by_title()` is somewhat problematic in that it can
return a post with a post status that may not be visible to the current
user, potentially leading to 404.
It is also somewhat flakey in that a change in post title within the admin
will potentially break a site using it to return a particular post.
Additionally, the lack of `orderby` clause results in undefined behavior
at a database level: different database engines and versions optimize the
query differently and return results using different indexes. (This
changed in 6.1 but is likely to be returned in 6.1.1 due to #57039).
I propose the function be deprecated in 6.2 as an API and developers
recommended to use `WP_Query` directly in the event they need to get a
post object by title.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/57041>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list