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

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.

share|improve this question
up vote 2 down vote accepted

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' );
share|improve this answer
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? – schizdazzle Aug 3 '11 at 14:09
wp_set_post_terms is a wrapper for wp_set_object_terms so they both basically do the same. – Bainternet Aug 3 '11 at 14:12
Many thanks once again! – schizdazzle Aug 3 '11 at 14:19
Glad i could help. – Bainternet Aug 3 '11 at 14:19

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.