#8348 closed defect (bug) (fixed)
get_posts behaviour altered
Reported by: |
|
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)
Change History (8)
#5
@
16 years ago
I think post_parent needs to default to null now that #8085 fixes the post_parent == 0 case.
#6
@
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:
- If the caller knows post_parent, caller should pass in an valid integer
- 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.
Should be test cases to be sure that no further regressions are made.