Ticket #6953 (closed defect: fixed)

Opened 2 months ago

Last modified 2 weeks ago

get_post() returns bogus object for non-existing post IDs

Reported by: Sam_a Assigned to: ryan
Priority: normal Milestone: 2.6
Component: General Version: 2.5.1
Severity: normal Keywords: get_post has-patch tested
Cc:

Description

It should return null or false instead.

var_dump( get_post( $dummy_id = -999 ));

returns

object(stdClass)(1) {
  ["ancestors"]=>
  array(0) {
  }
}

The object converts to boolean true, which can confuse things.

_get_post_ancestors($_post) is being called without checking that the previous query actually returned a post (in wp-includes/post.php).

Attachments

6953.patch (503 bytes) - added by Sam_a on 06/09/08 19:15:40.
get_post() returns &$null immediately for non-existing post IDs

Change History

05/13/08 18:49:59 changed by Sam_a

  • keywords changed from get_post to get_post has-patch needs-testing.

05/14/08 04:18:14 changed by ryan

  • owner changed from anonymous to ryan.

06/09/08 19:15:40 changed by Sam_a

  • attachment 6953.patch added.

get_post() returns &$null immediately for non-existing post IDs

06/10/08 18:19:38 changed by Sam_a

  • keywords changed from get_post has-patch needs-testing to get_post has-patch tested.

Attached 6953.patch fixes the problem in 2.5.1 and trunk.

For non-existing post IDs, get_post() now returns &$null immediately and doesn't call _get_post_ancestors(), wp_cache_add().

06/23/08 21:49:18 changed by ryan

  • milestone changed from 2.7 to 2.6.

06/23/08 21:50:22 changed by ryan

  • status changed from new to closed.
  • resolution set to fixed.

(In [8173]) Don't get post ancestors if post not found. Props Sam_a. fixes #6953