Programmatically Add Tag to WordPress Post Without Overwriting Pre-Existing Tags

I am able to add a tag to my post in code, but it overwrites the existing array of tags. Does anyone know of a way to add a tag to the array of pre-existing tags so that none are erased?

wp_set_object_terms($post_id, 'mytagname', 'post_tag');

This part of the WordPress API seems a bit clunky, but maybe I’m completely missing something. Any help would be appreciated!

Read More

Turns out RTFM was the answer.

Related posts

Leave a Reply

1 comment

  1. Look at the fourth parameter of the function – $append. If it is set to true, the tags are appended to the existing tags, if it’s false (the default) they replace them.

    So you want to call it like so:

    wp_set_object_terms($post_id, 'mytagname', 'post_tag', true);