Skip Navigation

[Resolved] Display number of total users, number of active users

This support ticket is created 3 years, 1 month ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Hong_Kong (GMT+08:00)

This topic contains 5 replies, has 2 voices.

Last updated by Luo Yang 3 years, 1 month ago.

Assisted by: Luo Yang.

Author
Posts
#2223471

Hello,

Several years ago I worked with a few Toolset technicians to develop a way to calculate the totals for fields filled out for a CPT. Now I would like to know how to display the total number of users.

I would also like to display the number of active users for a certain period of time.

I would also like to show the sum for certain fields for a given period of time. For instance, a custom field that collects money saved, but only showing money saved for the month of November.

Way back when we had developed the following code:

function count_numeric_custom_field_func( $atts ) {
global $wpdb;
extract( shortcode_atts( array(
'field' => '',
'cpt' => '',
'decimals' => 2,
'format_decimals' => 2,
), $atts ) );

$count = $wpdb->get_var( $wpdb->prepare(
"
SELECT SUM(CAST(meta_value AS DECIMAL (15,{$decimals}))) as count
FROM $wpdb->posts p
INNER JOIN $wpdb->postmeta pm
ON p.id = pm.post_id
WHERE p.post_type = %s
AND p.post_status = 'publish'
AND meta_key = %s
",
$cpt,
$field
) );
if (empty($count)){
$count = 0;
}

return number_format($count, $format_decimals);
}

add_shortcode( 'count_numeric_custom_field', 'count_numeric_custom_field_func' );

Thank you for your continued support.
Arrien

#2223817

Hello,

Q1) Now I would like to know how to display the total number of users.
It is possible with a user view, for example, you can try these:
Create a user view:
- Query users of users of "Any role"
- In section "Loop Editor", display shortcode [wpv-found-count]

Q2) I would also like to display the number of active users for a certain period of time.
There isn't such kind of built-in feature within Toolset or WordPress, you might consider other workaround, for example:
1) After user logged in your website, update a custom user field with current time value
2) Setup a user view:
- Query users
- Filter the result by the custom user field

Q3) I would also like to show the sum for certain fields for a given period of time.
Same as above, There isn't such kind of built-in feature within Toolset, and according to our support policy we don't provide custom codes support, in your case, I suggest you try to add post date range into the SQL query, for example:
hidden link

#2224153

Hi Luo,

Thank you for your feedback.

Is it possible to create a user view with Toolset Blocks or do I need to use the Legacy View plug-in?

Thanks,
A

#2224457

Blocks editor does not support user view, you need to setup the user view with classic editor.

If you are using Toolset Blocks plugin, you can enable classic editor by these:
Dashboard-> Toolset-> Settings-> General, in section "Editing experience", enable option: Show both the legacy and Blocks interface and let me choose which to use for each item I build
Then you can setup user view by these:
Dashboard-> Toolset-> Views

#2226991
user-views_2.png

Hi Luo,

I seem to be getting errors. I can't even see the name of the View when trying to select it in the View Block drop-down.

A

#2227361

As I mentioned above, Blocks editor does not support user view, you can display the user view by these:
Add a shortcode block, display the user view's shortcode, like this:
[wpv-view name="my-user-view"]

Please replace "my-user-view" with your user view's slug

More help:
https://toolset.com/documentation/user-guides/views-shortcodes/#wpv-view