I am working on listing all users similar to the Users page here on SE.
When listing each user, I want to add their 2 categories they have published most into. All categories are within Posts
.
Performance is essential, therefore I've come up with a sufficient solution:
- Make a function (with
$user_id
as argument) that returns category name of the user's two most published categories. - Create a daily
wp_schedule_event()
WP Cron that uses the above function and gets all users respective categories and finally adds it to each user's metadata viaadd_user_meta()
. - Simply get the users' categories via
get_user_meta()
on the Users page.
Currently, I have the cron and metadata codes ready, all I am missing is the function that returns the users top 2 categories. Can you help with this function?