In my custom post type what I am trying to do is say I have select drop down option called party_ad. The value of the options are obtained via an RSS feed.

echo '<select name="ad_Tags" id="ad_Tags">';
  foreach ($rs['items'] as $item)
   echo '<option value="'.$item[title].'" '. selected( $adTags, $item[title]).'>'.$item[title].'</option>';
  echo '</select>';

I can save these data with no problems - however, what I want to be able to save the selected option as a tag to the custom post. I thought about doing it front end, ie if an option is selected then it adds the value to the post tag box, ideally though, I'd like to really do this server side.

1 Answer 1


you can use wp_insert_term() to create the tag and then wp_set_object_terms() to set it as the custom post tag:

//get the tag
$tag = $_POST['ad_Tags'];
//create the tag
$term_id= wp_insert_term(
    $tag, // the term 
    'post_tag', // the taxonomy
    array('description'=> 'term description','slug' => 'term-slug')
//set the tag
wp_set_object_terms(  $post_id, $term_id, 'post_tag' );
  • Thanks for this - got it working, and just to clarify - if I wanted to say this with the post...ie the post is tagged as xyz. Could you not just use wp_set_post_terms instead? Commented Aug 3, 2011 at 14:09
  • wp_set_post_terms is a wrapper for wp_set_object_terms so they both basically do the same.
    – Bainternet
    Commented Aug 3, 2011 at 14:12
  • Glad i could help.
    – Bainternet
    Commented Aug 3, 2011 at 14:19

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.