I have worked out a function that will show me authors of a certain category, specifically based on post_type. This is fantastic, however I have two post_types that each have their own categories or tag_IDs. For example, I have two taxonomies: Fruit and Vegetable (or post_types). This code works to pull up only the authors that post in Fruit:
<?php
$args = array(
'post_type' => array('fruit'),
'exclude' => '1,2',
'optioncount' => true);
get_authors_by_post_type( $args );
?>
This is what I put in my functions.php to get this to work:
function get_authors_by_post_type($args){
global $wpdb;
$defaults = array(
'post_type'=>'post',
'exclude'=>'',
'exclude_admin' => true,
'echo' => true,
'optioncount' => false
);
$r = wp_parse_args( $args, $defaults );
extract( $r, EXTR_SKIP );
$post_type = (!is_array($post_type)) ? array($post_type) : $post_type;
foreach($post_type as $key=>$value) {
$post_type[$key]="'$value'";
}
$post_type = implode(',',$post_type);
$exclude = ($exclude) ? "AND p.post_author NOT IN ($exclude)" : '';
$sql = $wpdb->prepare("SELECT u.ID, p.post_author, COUNT(p.ID) as count, u.display_name
FROM $wpdb->posts p
JOIN $wpdb->users u ON p.post_author = u.ID
WHERE p.post_type IN ($post_type) AND p.post_status='publish' $exclude GROUP BY p.post_author ORDER BY u.user_registered");
$authors = $wpdb->get_results($sql);
$return = '<ul>';
foreach($authors as $author){
$posts = $author->count;
$author = get_userdata( $author->post_author );
$name = $author->display_name;
if ( $author->first_name != '' && $author->last_name != '' ) {
$name = "$author->first_name $author->last_name";
}
$link = '<a href="' . get_author_posts_url($author->ID, $author->user_nicename) . '" title="' . esc_attr( sprintf(__("Posts by %s"), $author->display_name) ) . '">' . $name . '</a>';
if ( $optioncount ) {
$link .= ' <span>('. $posts . ')</span>';
}
if (is_author($author->ID)) {
$return .= '<li class="current">'.$link.'</li>';
} else {
$return .= '<li>'.$link.'</li>';
}
}
$return .= '</ul>';
if ( ! $echo )
return $return;
echo $return;
}
Awesome. Now in Fruit, I have Oranges, Bananas and Apples. However if I plug in what appears to be their tag_ID or slug I cannot get anything to show up. Any thoughts on how I would pull this information? Any help would be MUCH appreciated as I am really determined to make this work.