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 have a taxonomy eg. authors. I want to create a custom UI for. I think integrating with a Meta Box together with other post meta will make things easier for the user. Also I think a jQuery UI AutoComplete (Multiple comma separated values) is more appropriate

So I will need to know how I can "update_post_taxonomy". I suppose I will need to

  • if taxonomy does not exists
    • create it
  • if post does not have the taxonomy term
    • add it
  • remove terms that are not specified by user

I am sure there are functions for this?

share|improve this question
add comment

1 Answer

up vote 1 down vote accepted

The function you are looking for is wp_set_post_terms()

which can create the terms if they don't exists and you can specify if to appended or replace existing terms. so you can remove all none user terms.

as for

if post does not have the taxonomy term , add it

you can use wp_get_post_terms() to check if the post has any terms of that taxonomy and if not then you can create and add using wp_set_post_terms() once again

share|improve this answer
    
wp_set_post_terms will check & add if terms exists for the post right? So I dont need to use wp_get_post_terms? Thats what I understand from the 1st part of your answer –  JM at Work Jun 29 '11 at 8:14
    
wp_set_post_terms will set the term and if it doesn't exists it will create it and then set it, wp_get_post_terms you can use to check if any term is set to that post –  Bainternet Jun 29 '11 at 9:00
    
What am I supposed to pass into the $tags argument? Term name or slug? Or will WordPress automatically resolve it? –  JM at Work Jun 30 '11 at 8:07
    
should work with both as far as i know –  Bainternet Jun 30 '11 at 8:32
add comment

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.