Opened 15 years ago
Closed 15 years ago
#20150 closed enhancement (duplicate)
allowing get_posts to exclude more than one author
| Reported by: | hugcape | Owned by: | |
|---|---|---|---|
| Priority: | normal | Milestone: | |
| Component: | Query | Version: | 3.3.1 |
| Severity: | minor | Keywords: | |
| Cc: | Focuses: |
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)
Change History (2)
Note:
See TracTickets
for help on using tickets.
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)
suggested patch