您是对的,不可能通过传递具有作者ID的数组来排除它们。原因在于wp-includes/query.php
在line 2294 - 2298
if ( strpos($q[\'author\'], \'-\') !== false ) {
$eq = \'!=\';
$andor = \'AND\';
$q[\'author\'] = explode(\'-\', $q[\'author\']);
$q[\'author\'] = (string)absint($q[\'author\'][1]); // this line select the first ID and only this ID
} else {
$eq = \'=\';
$andor = \'OR\';
}
您必须获得所有作者ID,然后排除不需要的作者,并向其余作者请求帖子
// array for user IDs
$users = array();
// roles to include
$roles = array( \'author\', \'editor\', \'contributor\', \'administrator\', \'superadmin\' );
// user IDs to exclude
$exclude = array( 2,3,5 );
// get all users
$_users = get_users();
foreach ( $_users as $user ) {
// do not add the user ID if the users role does not match or the users ID is excluded
if ( in_array( $user->ID, $exclude ) || ! in_array( $user->roles[0], $roles ) )
continue;
// add user
array_push( $users, $user->ID );
}
$args = array(\'author=\' . implode( \',\', $users );
$newquery = WP_Query( $args );