Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Update post terms

Tags:

php

wordpress

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?

like image 766
ScottMcGready Avatar asked Oct 23 '25 12:10

ScottMcGready


1 Answers

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!

like image 159
iEmanuele Avatar answered Oct 25 '25 03:10

iEmanuele