The function wp_set_post_terms() works fantastically however I'm looking to add some terms to a post at a later date. I've tried using wp_set_post_terms() and wp_set_object_terms() but they just overwrite what's already there. I thought wp_add_object_terms() was the answer to my question but it has the same functionality whereby overwriting the original terms.
Any way to append terms via code?
However, wp_set_object_terms(); seems made for your case:
From WordPress Codex:
Relates an object (post, link etc) to a term and taxonomy type (tag, category, etc). Creates the term and taxonomy relationship if it doesn't already exist.
<?php wp_set_object_terms( $object_id, $terms, $taxonomy, $append ); ?>
The clue
$append parameter is bool: if true, tags will be appended to the object. If false, tags will replace existing tags
Hope it helps!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With