Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I am using a custom post type in my website and a custom taxonomy for it.

An author selects one or many terms before publishsing its post.

My goal is to display authors pages in front end, so I am using author.php template file. This file is by default displaying the archive of posts written by the specific author. How can I add to this file the list of the custom taxonomy terms for the author published posts?

I give the following example if I wasn't clear in my explanation:

if Author-x has published:

**post1** with term1 , term2, term3
**post2** with term2, term5
**post3** with term1


then, in Author-x page I will have : term1, term2, term3, term5.

It is exactly the same principle as in user page in stack exchange. As you can see, there is a list of tags for each user which are tags of posts the user contributed in.

Thank you for your usual help.

share|improve this question
add comment

1 Answer

up vote 1 down vote accepted

First get a list of the author posts then loop over the each post and get the terms used ex:

function list_author_used_terms($author_id){

    // get the author's posts
    $posts = get_posts( array('post_type' => 'custom_post_type_name', 'posts_per_page' => -1, 'author' => $author_id) );
    $author_terms = array();
    //loop over the posts and collect the terms
    foreach ($posts as $p) {
        $terms = wp_get_object_terms( $p->ID, 'taxonomy_name');
        foreach ($terms as $t) {
            $author_terms[] = $t->name;
        }
    }
    return array_unique($author_terms);
}

//usage
echo implode(", ",list_author_used_terms(1));
share|improve this answer
    
Thank you @bainternet for your help. i will test and come back give feedback –  whiteletters and blankspaces Jun 10 '13 at 11:25
    
test away , but remember its an example :) –  Bainternet Jun 10 '13 at 11:26
    
I did all the necessary changes (changed post to custom post type name, and changed post_tag to my taxonomy name) but it is still giving me an empty array for author with id=1 even this author has posts with terms. also I print_r the $posts variable after get_posts and it is ok.!!!! –  whiteletters and blankspaces Jun 10 '13 at 12:00
    
It is okey and thank you very much, I understand now that you gave me just the algorithm not the code. but you should know that the only mistake you did is : name instead of term_name. Perfect Bainternet. –  whiteletters and blankspaces Jun 10 '13 at 12:08
1  
Glad you figured it out –  Bainternet Jun 10 '13 at 13:04
show 3 more comments

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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