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!
Turns out RTFM was the answer.
Look at the fourth parameter of the function –
$append
. If it is set totrue
, the tags are appended to the existing tags, if it’sfalse
(the default) they replace them.So you want to call it like so: