ID);
}
$args = array(
'post_type' => 'post',
'posts_per_page' => -1,
'author' => $author_id
);
$query = new WP_Query( $args );
$post_ids = wp_list_pluck( $query->posts, 'ID' );
$category_count = array(); // Count occurrences of each category
foreach ( $post_ids as $post_id ) {
$categories = wp_get_post_terms($post_id, 'category', array('fields' => 'ids'));
foreach ( $categories as $category_id ) {
if ( isset( $category_count[ $category_id ] ) ) {
$category_count[ $category_id ]++;
} else {
$category_count[ $category_id ] = 1;
}
}
}
arsort( $category_count ); // Sort by most frequent
$most_frequent_category_id = key( $category_count ); // Get the ID of the most frequent category
$most_frequent_category = get_category( $most_frequent_category_id ); // Get the category object for the most frequent category
if ( is_object( $most_frequent_category ) && property_exists( $most_frequent_category, 'slug' ) ) {
if ( array_key_exists( $most_frequent_category->slug, $category_colors ) ) {
$circle_color = $category_colors[ $most_frequent_category->slug ]; // Get the color for the most frequent category
} else {
$circle_color = '#CFCFCF'; // Default to black if the category color is not defined
}
} else {
$circle_color = '#CFCFCF'; // Default to black if the most frequent category is not an object or has no slug property
}
?>