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
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
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
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
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
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