Dear Beda,
I have a CP booking and I want to have a View to show the count summary of the booking belong to each author?
How can I set the query in View?
Best regards,
Kelvin.
Thank you for contacting us here in the Support Forum
1. I have a CP booking and I want to have a View to show the count summary of the booking belong to each author?
I understand you want the "Post count" for each author, where you count the Amount of Posts (Bookings) each WordPress user authored?
You can do this with the ShortCode wav-items-count, which gets the number of posts, users or taxonomies that will be displayed on the page.
https://toolset.com/documentation/views-shortcodes/#wpv-items-count
If paginated, use wav-found-count which displays the total number of posts, users or taxonomies that have been found by the Views query. This value is calculated before pagination, so even if you are using pagination, it will return the total number of posts matching the query.
https://toolset.com/documentation/views-shortcodes/#wpv-found-count
Since you want to count Posts, use this on a Post View, querying your Custom post type and set a query Filter to return only the Author's Posts you want to count-
Depends how you set / insert this View, but I recommend to pass the author with a ShortCode argument, so you can use the same View over and over again.
https://toolset.com/documentation/user-guides/passing-arguments-to-views/
Please let me know if you need further infos about this.
Thank you for your patience.
Dear Beda,
It seem both the [wpv-items-count] and [wpv-found-count] only show the count according to current page belonging to the author. This is not what I want.
For example, there are 100 booking belong to 10 authors in the site, I want to have a page to show the count summary for all authors at the same page.
Not sure whether any shortcode can simply passing the author id and then count the number of the bookings.
Best regards,
Kelvin.
Thanks for the Details
If you want to use Custom Code, you can build a User View, and use this ShortCode in your functions.php:
https://codex.wordpress.org/Function_Reference/count_user_posts
https://codex.wordpress.org/Shortcode_API
Example:
functions.php:
function user_posts_count($atts)
{
return count_user_posts($atts["user-id"], $atts["post-type"]);
}
add_shortcode( 'user-post-count', 'user_posts_count' );
Register the ShortCode in Views > Settings > Compatibility > 3rd party ShortCodes and then use it in your View listing Users as this:
[user-post-count user-id="[wpv-user field='ID']" post-type="post"]
Above will return the count of Posts a certain (in Loop) user has created.
Change "post" to your post type slug.
Please let me know if you need further infos about this.
Thank you for your patience.