How to set hierarchical terms to a post using wp_set_object_terms

Since wp_set_post_terms() does not accept hierarchy for it, you will first have to check if terms exist already, create them using wp_insert_term() if not and only then assign to post.

Note that there had been (don’t know current state) some cache related bugs with doing such things on the fly, see Inserting terms in an Hierarchical Taxonomy

Leave a Comment