in WordPress

Author Archive Widget in WordPress

In wordpress we can show the post archive widget easily but there is no easy way to show author archive widget. This small code snippet will help to show author archive widget in author page.

add_filter('getarchives_where', 'getarchives_where_author');
add_filter('month_link', 'month_link_author');
/**
* Custom function to filter query for author archive widget, this works on author page only
*
* @param $where
* @return string
*/
function getarchives_where_author($where){
global $wpdb, $wp_locale;
if(is_author()){
$curauth = (get_query_var('author_name')) ? get_user_by('slug', get_query_var('author_name')) : get_userdata(get_query_var('author'));
//var_dump($curauth);
$where .= ' AND post_author = '.$curauth->ID.' ';
}
return $where;
}
/**
* Custom function to filter author archive link for month
*
* @param $link
* @return string
*/
function month_link_author($link){
global $wpdb, $wp_locale;
if(is_author()){
$curauth = (get_query_var('author_name')) ? get_user_by('slug', get_query_var('author_name')) : get_userdata(get_query_var('author'));
//author_name=asaduzzeman
if(strpos($current_url, '?') !== false) {
$link .= '&author_name='.$curauth->user_login;
}
else{
$link .= '?author_name='.$curauth->user_login;
}
}
return $link;
}

Thanks