Error: getting incorrect user counts (by level)

I have a count of users per level/role at the top of my Users list in Wordpress that has always been very accurate, but out of the blue one day changed to be incorrect. For example, one of the levels, when empty shows as “-4”!

These counts seem to be updating correctly (when a user is changed to a new level it increases by 1, when changed back, the level decreases by 1, etc.) but are inherently wrong. How can I correct this please?

Oh! I had not seen something like that before! That’s so strange… Seems to be a wordpress thing…

This does not look like an s2Member-specific count issue. Those counts at the top of the native WordPress Users screen are generated by WordPress core, not by s2Member. Core uses count_users() against the WordPress capabilities usermeta for role counts.

A negative count is especially suspicious, because that points more toward bad role/usermeta data, or another plugin / custom code filtering or altering the counts, rather than s2Member itself.

:slight_smile:

Thanks!

1 Like

The following code should count the number of user in either multiple levels or the commented out line will count users in one level only.

$roles = array('s2member_level4', 's2member_level5');
$wp_user_query = new WP_User_Query(array('role__in' => $roles));

//$wp_user_query = new WP_User_Query(array('role' => 's2member_level4'));

$members = $wp_user_query->get_results();

echo count($members);

Thank you. Turned out to be a clash with a plugin.

2 Likes