[wp-trac] [WordPress Trac] #56399: get_page_by_title() Is Not Checking "publish" Post Status

WordPress Trac noreply at wordpress.org
Thu Aug 18 14:12:29 UTC 2022


#56399: get_page_by_title() Is Not Checking "publish" Post Status
--------------------------------------+----------------------
 Reporter:  xmic                      |       Owner:  (none)
     Type:  enhancement               |      Status:  closed
 Priority:  normal                    |   Milestone:
Component:  Posts, Post Types         |     Version:
 Severity:  normal                    |  Resolution:  wontfix
 Keywords:  has-patch has-unit-tests  |     Focuses:
--------------------------------------+----------------------
Changes (by johnbillion):

 * status:  new => closed
 * version:  trunk =>
 * resolution:   => wontfix
 * milestone:  Awaiting Review =>


Comment:

 There's nothing specific about the `get_page_by_title()` function which
 suggests that it only returns published posts, and there are many
 functions in WordPress that can return unpublished content. Unfortunately
 if a developer is using it this way then that's a mistake. As noted above,
 the status of the returned post should be checked if only a published post
 is required.

 In addition, fetching a post by its title is not a particularly reliable
 solution for a client site. If they decide to change the title one day
 then their site will break. Using an explicit option so the appropriate
 page can be selected and then fetching the page by its ID is much more
 reliable.

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/56399#comment:9>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list