#48382 closed defect (bug) (duplicate)
do_action convert array of post to single post object if array contain only 1 post
Reported by: | fabienlege | Owned by: | |
---|---|---|---|
Milestone: | Priority: | normal | |
Severity: | normal | Version: | 5.3 |
Component: | Plugins | Keywords: | |
Focuses: | Cc: | ||
PR Number: |
Description
in wp-includes/plugin.php line 456, function do_action automaticaly convert array of one post to single post object.
code to reproduce bug :
<?php $posts = get_post($args); // this return an array on 0,1 or more wp_post objects. do_action('test',$posts); add_action('test',function($posts){ var_dump($posts); // if $posts is empty array, we have an empty array. if its an array of multiple posts, we have an array of multiple posts. but, if an array of one post is passed to parameter, we have a single wp_post object (not in an array). })
It's a real problem if you need to do action on get_posts result. you don't know if the result is 0, 1 or more post and, forexemple, a foreach fail
Change History (2)
Note: See
TracTickets for help on using
tickets.
Hi @fabienlege, and thanks for filing this report. This issue is being tracked in #47438.