Make WordPress Core

Opened 13 years ago

Closed 13 years ago

#20150 closed enhancement (duplicate)

allowing get_posts to exclude more than one author

Reported by: hugcape's profile hugcape Owned by:
Milestone: Priority: normal
Severity: minor Version: 3.3.1
Component: Query Keywords:
Focuses: Cc:

Description

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.

Attachments (1)

get_posts-exclude-more-than-1-author.patch (652 bytes) - added by hugcape 13 years ago.
suggested patch

Download all attachments as: .zip

Change History (2)

#1 @ocean90
13 years ago

  • Milestone Awaiting Review deleted
  • Resolution set to duplicate
  • Status changed from new to closed
Note: See TracTickets for help on using tickets.