0

On the author template, I would like to display a list of the custom taxonomies associated to the posts written by that author.

In details: I have a "clubs" taxonomy, which is non-hierarchical and applies to Posts.

On the author template, I need to display a list of the "clubs" used by that author's Posts, as links. In this manner, i can list the clubs to which this author participates in.

Is that possible?

1
  • Did you tried anything ? You can try first getting all of the post ids by author and then wp_get_object_terms functions to retrieve the terms by taxonomy and object_ids
    – Shazzad
    Feb 12, 2014 at 0:42

1 Answer 1

1

First grab the post ids by the author, and then the terms.

$author_id = '1234';
$taxonomy = 'clubs';

$post_ids = get_posts('fields=ids&post_type=post&post_status=publish&showposts=-1&author='. $author_id );
$clubs = wp_get_object_terms($post_ids, array($taxonomy));

$html = '<ul>';
foreach( $clubs as $club )
{
    $html .= sprintf( 
        '<li><a href="%1$s">%2$s</a></li>',
        get_term_link($club, $taxonomy),
        $club->name
    );
}
$html .= '</ul>';

echo $html;
1
  • Hello Shazzad, Thank you it works quite nicely, except that if a tag has been used in 2 posts, it will appear twice. But you've sent me in the right direction, so i'll pick this up as the right answer.
    – pixeline
    Feb 12, 2014 at 8:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.