Make WordPress Core

Opened 4 years ago

Closed 4 years ago

Last modified 4 years ago

#48382 closed defect (bug) (duplicate)

do_action convert array of post to single post object if array contain only 1 post

Reported by: fabienlege's profile fabienlege Owned by:
Milestone: Priority: normal
Severity: normal Version: 5.3
Component: Plugins Keywords:
Focuses: Cc:


in wp-includes/plugin.php line 456, function do_action automaticaly convert array of one post to single post object.

code to reproduce bug :

$posts = get_post($args); // this return an array on 0,1 or more wp_post objects.
    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)

#1 @dlh
4 years ago

  • Milestone Awaiting Review deleted
  • Resolution set to duplicate
  • Status changed from new to closed

Hi @fabienlege, and thanks for filing this report. This issue is being tracked in #47438.

#2 @SergeyBiryukov
4 years ago

  • Component changed from General to Plugins
Note: See TracTickets for help on using tickets.