Problem:
The issue here is that the customer wanted to count the number of users who have created posts under a specific post type.
Solution:
This is actually something that will require a bit of custom coding to achieve.
Here below is a small snippet that was written to help resolve this.
function count_users_with_posts() { $blogusers = get_users(); $user_count = array(); foreach($blogusers as $user){ $args = array( 'post_type' => 'covid-19-info', 'author' => $user->ID, ); $wp_posts = get_posts($args); if(count($wp_posts) > 0){ array_push($user_count, $user->ID); } } return count($user_count); } add_shortcode( 'count_users_with_posts', 'count_users_with_posts' );
Add the above to your Toolset custom code section in Toolset->Settings->Custom Code and activate it. You will need to replace "covid-19-info" with the slug of your post type that you want to count the users for.
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.
Our next available supporter will start replying to tickets in about 3.96 hours from now. Thank you for your understanding.
Sun | Mon | Tue | Wed | Thu | Fri | Sat |
---|---|---|---|---|---|---|
- | 9:00 – 12:00 | 9:00 – 12:00 | 9:00 – 12:00 | 9:00 – 12:00 | 9:00 – 12:00 | - |
- | 13:00 – 18:00 | 13:00 – 18:00 | 13:00 – 18:00 | 14:00 – 18:00 | 13:00 – 18:00 | - |
Supporter timezone: America/Jamaica (GMT-05:00)
This topic contains 6 replies, has 2 voices.
Last updated by 4 years, 2 months ago.
Assisted by: Shane.