Here are some different approaches:
-
Fetch users with
get_users()and paginate them with e.g. 10 per page.
For each user, callWP_Querywithdate_queryfor the last 24 hours, else last week. Useauthorinput argument andposts_per_pageas 1 (we don’t need more) and get the total posts fromWP_Query::found_posts.- pros: Uses only WordPress API calls
- cons: Multiple
WP_Querycalls, but we limit them by the user per page count.
-
Fetch all posts last 24 hours or last week with
WP_Queryanddate_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_Querycall. - 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.