Make WordPress Core

Opened 18 years ago

Closed 18 years ago

#6953 closed defect (bug) (fixed)

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

Reported by: sam_a's profile Sam_a Owned by: ryan's profile ryan
Milestone: 2.6 Priority: normal
Severity: normal Version: 2.5.1
Component: General Keywords: get_post has-patch tested
Focuses: 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 (1)

6953.patch (503 bytes) - added by Sam_a 18 years ago.
get_post() returns &$null immediately for non-existing post IDs

Download all attachments as: .zip

Change History (6)

#1 @Sam_a
18 years ago

  • Keywords has-patch needs-testing added

#2 @ryan
18 years ago

  • Owner changed from anonymous to ryan

@Sam_a
18 years ago

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

#3 @Sam_a
18 years ago

  • Keywords tested added; needs-testing removed

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().

#4 @ryan
18 years ago

  • Milestone changed from 2.7 to 2.6

#5 @ryan
18 years ago

  • Resolution set to fixed
  • Status changed from new to closed

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

Note: See TracTickets for help on using tickets.