How to get the count of the WP_User_Query result while I use

$query = new WP_User_Query( $args );
echo count($query);

It returns 1 when there is no user. But I need 0 in that case.

How can I get the count of users?


You should use a total_users property:

$query = new WP_User_Query( $args );    

or get_total method:

$query = new WP_User_Query( $args );    
$query-> get_total();

Docs are your friend: https://codex.wordpress.org/Class_Reference/WP_User_Query

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.