It seem wp_query have the problem where it does not accept more than 1 negative value in author argument. for example:
$args = array('author=-2,-3,-4');
$newquery = WP_Query($args);
This grab everything else. Simply doesn’t work.
I found this trac, but seem still no official patch for this.
Any suggestion?
You are right, it is not possible to pass an array with author IDs to exclude them. The reason is in
wp-includes/query.php
at line 2294 – 2298You have to get all author IDs, then exclude the unwanted authors and request the posts from the remaining authors
As of WordPress version 3.7 (released in October 2013), you can now use
author__in
andauthor__not_in
to pass an array of author IDs. Note that they both use two underscores after the word “author”.Here’s how you would exclude author IDs 2, 3, and 4:
Here’s a link to the codex.
Here’s a link to the developer docs.
I didn’t realize it before, but it seems that you currently can’t exclude multiple authors posts using WP_Query, I’ve updated the Codex to be less misleading.
Here is a way to exclude posts from multiple authors using the $wpdb class:
?>
“UNTESTED” but could you do it this way?
This is a function I picked up here for excluding categories. Not sure if it could be used to exclude by author but it is far better than writing a custom query if it works