list tags with count in author profile page

I would like to list tags with count in author profile page just like this page

If the user click the tag, then I would like to list the tagged posts.

Read More

Can someone help me?

Related posts

Leave a Reply

1 comment

  1. Here you go:

    function get_author_post_tags_wpa78489($author_id,$taxonomy = 'post_tag'){
        //get author's posts
        $posts = get_posts(array(
            'author' => $author_id,
            'posts_per_page' => -1,
            'fields' => 'ids'
            )
        );
    
        $ts = array();
    
        //loop over the post and count the tags
        foreach ((array)$posts as $p_id) {
            $tags = wp_get_post_terms( $p_id, $taxonomy);
            foreach ((array)$tags as $tag) {
                if (isset($tags[$tag->term_id])){ //if its already set just increment the count
                    $ts[$tag->term_id]['count'] = $ts[$tag->term_id]['count']  + 1;
                }else{ //set the term name start the count
                    $ts[$tag->term_id] = array('count' => 1, 'name' => $tag->name, 'slug' => $tag->slug);
                }
            }
        }
    
        //so now $ts holds a list of arrays which each hold the name and the count of posts 
        //that author have in that term/tag, so we just need to display it
        $url = get_author_posts_url($author_id);
        echo '<ul>';
        foreach ($ts as $term_id => $term_args) {
            echo '<li><span class="count">'.$term_args['count'].'</span> <a href="'.add_query_arg('tag',$term_args['slug'],$url).'">'.$term_args['name'].'</a></li>';
        }
        echo '</ul>';
    }