WordPress Post tags (get_the_tags & has_tag)

I actually debugged this and found the problem. It is directly related to creating a post via the REST API.

I have found that when a post is created via the REST API that the hook callbacks happen in a different order from a post created with the admin UI. Specifically when the REST API calls wp_insert_post the data does not include any tags passed in via the JSON data. This means that if a plugin has a publish_post action set and needs to query the tags for the new post it will always fail. Setting a set_object_terms action and querying for the tags gives the right result. The problem is that the set_object_terms action happens AFTER the publish_post action. It is expected that when the publish_post is called that the tags are available for the new post.

Leave a Comment