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

Which' WordPress function is used in programmatically associating the term taxonomy IDs with post IDs?

And does that function have internal mechanisms to make sure no duplicate entries are allowed even if the records were to be added programmatically?

Here of course I'm not talking about wpdb->insert.

share|improve this question

While the code does check for duplicates, the schema itself won't allow it because the term_relationships table has a PRIMARY KEY of (object_id,term_taxonomy_id).

share|improve this answer

I believe the function you are looking for is wp_set_object_terms(). You will need to ensure that you are not giving duplicate IDs when append is set to false. I'm not sure what the behavior is when append is set to true.

EDIT: Having read through the source code for the function, it looks like if you're appending, then it does check for duplicates.

share|improve this answer

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.