WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have this really simple setup where I loop through an array of actors, and for each actor name I successfully insert a term. Then I use wp_set_post_terms to assign the terms to a post, but this only assigns the last term to that post. I am new to using taxonomy/terms so maybe there's an obvious solution. Here's my code:

foreach ($cast as $actor) {

    $actor_term_id = wp_insert_term( $actor[name], 'actor', array(
        'description' => $bio[0]["desc"]

    // Assign term id to post
    wp_set_post_terms( $post_id, $actor_term_id, 'actor' );

share|improve this question
up vote 1 down vote accepted

You need send a fourth argument to the function:

wp_set_post_terms($post_id, $actor_term_id, 'actor', true);

Each time the function executes, you're replacing any existing terms. The fourth argument specifies that you wish to append them.


share|improve this answer
I see, thanks. However, I noticed an issue: I can only assign an actor term to one post this way. If I use the function in a loop that has an actor name that was already added and assigned to a post before, it won't assign that term to another post... – Marc Sep 29 '12 at 18:40
I don't believe that this is an issue with WordPress, that's just how you chose to setup your loop. From WordPress' perspective, you can assign many terms to many posts. – NightHawk Sep 29 '12 at 19:11

Your Answer


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.