I’d like to be able to filter my sidebar widgets (tag cloud, category, archive) to only show those tags/categories/months that apply to a given author on the author template.
What is the correct way to filter or modify these widgets? I found this page in the codex but it doesn’t seem that the native functions for any of the widgets can accept an author id as a parameter.
It’s a bit unwieldy to just grab all posts by an author and filter through them to only return a category list. If you wish to use the default widgets in the sidebar and have them filtered by the author only on the author template then I’d suggest using the following approach.
First, filter the tag and category widget queries for categories and tags.
Then using the dependent method to retrieve taxonomy ids filtered by the user ID.
source: https://gist.github.com/codearachnid/9655690
There is no built in way to do this, and I don’t know that it’s been tried before. That being said, the tools are all there, you have to put them together.
You can get the current User ID with
$userid = wp_get_current_user()
You can then get all posts by a user with
$posts = WP_Query('author='.$userid)
Then loop through all posts by the author, and append the categories of each post in an array. For example,
Then use the
array_unique()
function to remove duplicates.Lastly, foreach through each category, and get a link to the category with
get_category_link()
I haven’t tested this but you could try