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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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