I have been googling around but could not find the “add tag to post” api/codex. Does anyone know what it is ? Also, the “delete tag from post”.
Thanks.
I have been googling around but could not find the “add tag to post” api/codex. Does anyone know what it is ? Also, the “delete tag from post”.
Thanks.
You must be logged in to post a comment.
You’ll find an index of a good chunk of the WordPress API here on codex. The function you want is wp_set_post_tags(), but follow the links from that page to related functions.
Edit: this should remove a tag from a post, per comment below
You would use the
wp_insert_term()
function to insert a new tag:Then after creating your terms, you would add them to the post of your choice using the
wp_set_post_terms()
function, like so:Google Knows it.
If you wanted to add a categories to a post with the ID of 42:
If you wanted to clear/remove all categories from a post with the ID of 42:
read more about wp_set_object_terms