Make WordPress Core

Opened 16 years ago

Closed 16 years ago

Last modified 15 years ago

#8348 closed defect (bug) (fixed)

get_posts behaviour altered

Reported by: hailin's profile hailin Owned by:
Milestone: 2.7 Priority: normal
Severity: normal Version:
Component: General Keywords: needs-patch needs-test-cases
Focuses: Cc:

Description

After recent changes in get_posts, probably related to: #7326, get_posts returned false whereas previously returned a valid value.

The specific call is from a wpmu plugin:

if ( !$posts =& get_posts( array('meta_key' => '_vidavee', 'meta_value' => $asset_id, 'post_type' => 'attachment', 'post_status' => 'inherit') ) )

return false;

Given the same parameters, the call used to return a valid attachment post. Now it returns false.

The root cause is in function get_posts($args = null) in wp-includes/post.php.
When I comment out 'post_parent' => 0 in $defaults array, the above get_posts call will continue to return valid result.

Not sure why we added 'post_parent' => 0 in the first place. Also not sure if we remove 'post_parent' => 0, whether it will cause other side effects.

One walk-around is to add post_parent='post' to the wpmu get_posts call, but it's kind of weird that we had to do that. And if we don't address this in the core, ALL
other similar calls need to be amended similarly.

Attachments (1)

8348_post_parent.diff (549 bytes) - added by hailin 16 years ago.
patch

Download all attachments as: .zip

Change History (8)

#1 @jacobsantos
16 years ago

  • Keywords needs-patch needs-test-cases added

#2 @jacobsantos
16 years ago

Should be test cases to be sure that no further regressions are made.

#3 @jacobsantos
16 years ago

Well, unless said "regression" is intended behavior.

#4 @ryan
16 years ago

Perhaps related to #8085.

#5 @ryan
16 years ago

I think post_parent needs to default to null now that #8085 fixes the post_parent == 0 case.

#6 @hailin
16 years ago

If there are no other cases which assumes, and whose behaviors rely on, the default post_parent=0 value, I think we can remove 'post_parent' => 0.

Basically the logic should be:

  1. If the caller knows post_parent, caller should pass in an valid integer
  1. If the caller doesn't know post_parent, get_posts should honor caller's true intention, which is "I don't know whom my daddy is, it can be anyone in the world; could be 0 or any other value", thus should not assume it is 0.

After removing it, the wpmu plugin call works fine.

I don't have other regression cases.

@hailin
16 years ago

patch

#7 @ryan
16 years ago

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

(In [9906]) Don't set post_parent default. Props hailin. fixes #8348

Note: See TracTickets for help on using tickets.