users - How to get the count

admin2025-06-06  1

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?

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?

Share Improve this question edited Nov 1, 2018 at 10:42 Krzysiek Dróżdż 25.6k9 gold badges53 silver badges74 bronze badges asked Nov 1, 2018 at 8:26 Sammu SundarSammu Sundar 1033 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 2

You should use a total_users property:

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

or get_total method:

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

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

转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1749214817a317325.html

最新回复(0)