Here are some different approaches:
-
Fetch users with
get_users()
and paginate them with e.g. 10 per page.
For each user, callWP_Query
withdate_query
for the last 24 hours, else last week. Useauthor
input argument andposts_per_page
as 1 (we don’t need more) and get the total posts fromWP_Query::found_posts
.- pros: Uses only WordPress API calls
- cons: Multiple
WP_Query
calls, but we limit them by the user per page count.
-
Fetch all posts last 24 hours or last week with
WP_Query
anddate_query
. Loop through the posts and collect posts count for each post author per week or per 24 hours.- pros: Uses only WordPress API calls – single
WP_Query
call. - cons: Doesn’t scale well for many posts as we don’t want to fetch hundreds of posts!
- pros: Uses only WordPress API calls – single
-
Write custom SQL
- pros: Dedicated single query or queries.
- cons: More fragile as the SQL is written by hand and we’re not using WordPress API calls. Gets complicated if we use e.g. joins and that might become slower as the tables grow.