[wp-trac] [WordPress Trac] #33068: get_post() returning current object if 0

WordPress Trac noreply at wordpress.org
Mon Feb 8 22:12:08 UTC 2021


#33068: get_post() returning current object if 0
---------------------------------------+---------------------
 Reporter:  Rahe                       |       Owner:  (none)
     Type:  defect (bug)               |      Status:  new
 Priority:  normal                     |   Milestone:  5.7
Component:  Posts, Post Types          |     Version:  3.5
 Severity:  normal                     |  Resolution:
 Keywords:  needs-testing 2nd-opinion  |     Focuses:
---------------------------------------+---------------------

Comment (by peterwilsoncc):

 I agree with @johnbillion that this is a wontfix due to backward-
 compatibility concerns.

 The documentation could be improved to indicate:
 * A falsey value returns the current global post inside the loop
 * A numerically valid post ID that points to a non-existent post returns
 `null`.

 @Rahe You're right be the behavior of an invalid ID is a little
 inconsistent (0 returns the global, a negative number or float returns
 `null`). For valid IDs it's consistent but the return types differ.

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


More information about the wp-trac mailing list