Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
  • #18199


    May I know it is possible to get view count for each user role? I would like to know the total count post views for different user role instead of only exclude specific user role.

    Thank you!



    There’s no direct way to do it but this can be achieved using two queries.

    1. Get the user ids of a specific role by get_users() function and ‘role__in’ parameter
    2. Then use the user ids you got to run a WP Query – here set the ‘author__in’ parameter with the user ids (to get posts of specific user roles) and set ‘orderby’ parameter to ‘post_views’ (to get post views data along with other post data).
    3. In result PVC will extend the WP Query data with ‘total_views’ property giving you a sum of all the views of the posts found in the WP Query call.

Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.