It happens so that upon addition/update of certain meta key I need to do some actions and add custom taxonomy terms to a post. Let's say that addition is like this (and it works perfectly if called from 'publish_post' action but at this point post meta value I need is not available)
if (count($entities)>0)
{
foreach ($entities as $entity)
{
if (!term_exists($entity, 'entity'))
{
wp_insert_term($entity, 'entity');
}
}
wp_set_object_terms($post_id, array_map('sanitize_title', $entities), 'entity', false);
}
The weirdest thing is that wp_set_object_terms
returns array of term_taxonomy_ids of terms, meaning it inserted them successfully (according to Codex) but they're actually not there. Any ideas what I might be missing here?