The user_status
field has long been no longer used in core, so maybe that’s why there is no argument that will filter the users by their user_status
value?
However, you can use the pre_user_query
hook to alter the user query’s SQL command, i.e. to add something like a AND user_status = 0
into the WHERE clause.
So for example, you can add this into your theme’s functions.php
file, and then just set the user_status
argument, e.g. get_users( 'user_status=0' )
(like you did in your first example):
add_action( 'pre_user_query', 'my_pre_user_query' );
function my_pre_user_query( $query ) {
if ( isset( $query->query_vars['user_status'] ) ) {
$query->query_where .= " AND user_status = " . (int) $query->query_vars['user_status'];
}
}
Alternatively, you could just make a custom instance of WP_User_Query
, then set the WHERE condition the same way it’s set above (i.e. via direct modification on the $query_where
property), like so:
$query = new WP_User_Query;
$query->prepare_query( [
'orderby' => 'ID',
'order' => 'DESC',
// don't set user_status
'number' => $limit,
] );
// Now modify the WHERE clause.
$query->query_where .= " AND user_status = 0";
// Then run the SQL command.
$query->query();
$users = $query->get_results();
var_dump( $users );