Opened 3 weeks ago
Last modified 7 days ago
#65078 new enhancement
get_page_by_title should not be deprecated
| Reported by: |
|
Owned by: | |
|---|---|---|---|
| Milestone: | Awaiting Review | Priority: | normal |
| Severity: | normal | Version: | 6.2 |
| Component: | Posts, Post Types | Keywords: | close |
| Focuses: | Cc: |
Description (last modified by )
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_postsandposts_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.
These direct methods introduced some flaky issues very hard to maintain as suggested by @peterwilsoncc back in the day. I cannot see the problem of a more generalistic solution for this trivial thing.
It's a very trivial implementation, and deprecated things never fade in WP so you can basically keep using it despite you will get the deprecated messages in the log.
The deprecation was for good, and many legacy things still need some degree of deprecation yet, but there isn't much time for devs to go through all of them.