[wp-trac] [WordPress Trac] #20006: get_comments (and WP_Comment_Query) does not accept multiple post_type

WordPress Trac wp-trac at lists.automattic.com
Fri Feb 10 05:46:52 UTC 2012


#20006: get_comments (and WP_Comment_Query) does not accept multiple post_type
--------------------------+-----------------------------
 Reporter:  Justin_K      |      Owner:
     Type:  defect (bug)  |     Status:  new
 Priority:  normal        |  Milestone:  Awaiting Review
Component:  Comments      |    Version:  3.3.1
 Severity:  normal        |   Keywords:
--------------------------+-----------------------------
 Although get_comments was recently improved to support post_types, it does
 not seem to properly handle MULTIPLE post_types.

 Suppose you need to get the most recent comments for posts, pages, and
 attachments (attachments don't seem to be included by default).  The
 following doesn't work, as it only returns comments on attachments (or
 whichever status is listed first):
  {{{
 get_comments(array('number'=>20, 'status'=>'approve',
 'post_type'=>array('attachment','post','page')));
 }}}

 The following doesn't work either, only returning the default post/page
 comments (taken from the example for multiple category handling at
 http://codex.wordpress.org/Class_Reference/WP_Query):
  {{{
 get_comments(array('number'=>20, 'status'=>'approve',
 'post_type__in'=>array('attachment','post','page')));
 }}}

 A quick look at wp-includes/comment.php, line 327 (WP v3.3.1) shows that
 the 2nd option will be array_filter'ed away.  Immediately below, all of
 the WHERE clauses are hardcoded as "=", which is why there's no way to
 specify more than one.  As a result, it seems like the only way to get
 recent comments on posts,pages,and attachments (or any other subset of >1
 post_type) is to do multiple calls to get_comments (i.e. one with default
 params and one for attachments) then merge the results
 together...effectively requiring twice the work.

-- 
Ticket URL: <http://core.trac.wordpress.org/ticket/20006>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software


More information about the wp-trac mailing list