[wp-trac] [WordPress Trac] #56399: get_page_by_title() Is Not Checking "publish" Post Status
WordPress Trac
noreply at wordpress.org
Wed Aug 17 21:35:41 UTC 2022
#56399: get_page_by_title() Is Not Checking "publish" Post Status
----------------------------+--------------------------------------
Reporter: xmic | Owner: (none)
Type: enhancement | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Bootstrap/Load | Version: trunk
Severity: normal | Keywords: has-patch has-unit-tests
Focuses: |
----------------------------+--------------------------------------
Hello,
**Issue**
It is common expectation to use `get_page_by_title()` for us to get the
published page that we wish to use. However, the current implementation
does not take into consideration the `post_status` in the query.
**Common Use Case Scenario**
The current issue is that `get_page_by_title()` will get the draft post,
and if this is used in conjunction with obtaining the URL, it will result
in a 404 error for users.
**Solution**
Therefore, to take it a step further, we can introduce another parameter
$post_status which accepts as a string or array of `post_status`
defaulting to `'publish'`.
This way, the function will not return a non-SEO friendly page, for
example, if that page had been sent to the draft, because a user wishes to
"re-create" the page without binning the previous one.
- Michael
--
Ticket URL: <https://core.trac.wordpress.org/ticket/56399>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list