[wp-trac] [WordPress Trac] #65078: get_page_by_title should not be deprecated
WordPress Trac
noreply at wordpress.org
Thu Apr 16 02:40:21 UTC 2026
#65078: get_page_by_title should not be deprecated
-------------------------------+-----------------------------
Reporter: hybridwebdev | Owner: (none)
Type: enhancement | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Posts, Post Types | Version:
Severity: normal | Keywords: 2nd-opinion
Focuses: |
-------------------------------+-----------------------------
This ticket is in reference to #57041.
While the original ticket was resolved, I believe deprecating
get_page_by_title() introduces a gap in the API that is not fully
addressed by WP_Query.
The key issue is not convenience, but determinism.
get_page_by_title() performs a direct database lookup using an exact match
on title. This approach:
- avoids global query filters such as pre_get_posts and posts_clauses
- guarantees more consistent results immune to external modifications
- provides a clear and narrowly scoped intent: retrieve a page/post by
exact title
In contrast, using WP_Query for this purpose introduces variability. Even
when attempting to replicate exact-match behavior, the query remains
subject to global hooks and filters, which may alter the SQL in ways that
are outside the caller’s control. This makes it difficult to guarantee
equivalent behavior in plugin-heavy environments. Additionally, this can
be subject to performance degradation when lots of logic-heavy filters are
present. This could even result in queries where posts the user cannot
access are returned. Which is one of the issues this commit was meant to
resolve.
A previous attempt to migrate this function to WP_Query was reverted due
to unintended side effects. While that specific issue related to ordering,
it highlights a broader concern: WP_Query is not suitable as a drop-in
replacement for this method.
Deprecating this function effectively requires developers to reimplement
its logic. This leads to duplicated boilerplate and inconsistent
implementations across codebases.
Finally, low level methods like this serve a specific purpose. They're not
intended to catch edge cases. That responsibility is on the code that uses
the method.
Given this, it may be worth reconsidering whether get_page_by_title()
should remain as a low-level helper for exact, unfiltered lookups.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/65078>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list