Your question is slightly ambiguous, but I read it this way: given an author and you want to know the three categories in which has published most posts. Let’s use wp_query
to get there.
$author="johndoe";
$author_posts = new WP_Query (array (
'author' => $author,
'posts_per_page'=>-1,
));
Now we have an array of all posts by this author. Sadly it’s not possible to order them by category (because a post may have multiple categories), let alone by amount of posts per category. So we’ll have to loop through the results and do the counting ourselves.
$cat_array = array();
if ( $author_posts->have_posts() ) {
while ( $author_posts->have_posts() ) {
$author_posts->the_post();
$cat_array[] = wp_get_post_categories(get_the_ID(),array('fields'=>'names'));
}
}
This gives an array $cat_array
which simply holds all the categorie names of all the author’s posts. We will have to count the duplicates to see which category is used most. There’s a PHP function for that: array_count_values
.
$cat_count = array_count_values($cat_array);
$cat_count = arsort($catcount); // sorts an array by value from high to low
We end up with $cat_count
holding the list of categories by this author from high to low occurence. Depending on what you want you could use this information to loop through $author_posts
again or do a new query to get all the posts in the three top categories:
$author="johndoe";
$top_cats = $cat_count[0] . ',' . $cat_count[1] . ',' . $cat_count[2];
$author_posts = new WP_Query (array (
'author' => $author,
'posts_per_page' =>-1,
'category_name' => $top_cats,
));
Beware that this is a fairly expensive procedure in terms of computation. Also note that I didn’t test this code, so some debugging may be necessary.