[wp-trac] [WordPress Trac] #20150: allowing get_posts to exclude more than one author

WordPress Trac wp-trac at lists.automattic.com
Thu Mar 1 20:04:36 UTC 2012


#20150: allowing get_posts to exclude more than one author
-------------------------+-----------------------------
 Reporter:  hugcape      |      Owner:
     Type:  enhancement  |     Status:  new
 Priority:  normal       |  Milestone:  Awaiting Review
Component:  Query        |    Version:  3.3.1
 Severity:  minor        |   Keywords:
-------------------------+-----------------------------
 I'm trying to exclude more than one author from the posts list this way:

 {{{
 query_posts( array('author'=>'-1,4',...));
 }}}

 but only the first one author_id is taken into account. I found at wp-
 includes/query.php, function get_posts, line 2282:
 (I'm adding the $q!['author'] debug as a comments)
 {{{
  if ( strpos($q['author'], '-') !== false ) {          #DBG: $q['author']
 = "-1,4"
        $eq = '!=';
        $andor = 'AND';
        $q['author'] = explode('-', $q['author']);      #DBG: $q['author']
 = array("", "1,4")
        $q['author'] = (string)absint($q['author'][1]); #DBG: $q['author']
 = "1"
 } else {
        $eq = '=';
       $andor = 'OR';
 }
 $author_array = preg_split('/[,\s]+/', $q['author']);  #DBG: $author_array
 = array("1")

 }}}

 I think the (string)absint should be removed from line 2282, so the
 $author_array value will be array("1", "4") which is the result we want.

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


More information about the wp-trac mailing list