`save_post` action is triggered before term_relationships is updated
-
I’m writing a routine that extracts certain posts and their related categories/tags from the database every time a post is saved but have noticed what may be a bug.
If saving a post where only the categories or tags are changing, the
term_relationships
table (and/or other term-related tables) are not updated until aftersave_post
is triggered. If the post is being saved with any changes in addition to the category or tag (e.g., the title or content), then the term_relationships are updated beforesave_post
is called.e.g., If I change only the category and click “update” my
save_post
callback-function’s query to the database doesn’t see the new category assigned to this post (it looks like it did before the change since the category was the only update). If I then make a 2nd change to only the category in that post, the query retrieves the previous change, but doesn’t see the latest change. If I then change the title of the post only (no category change), the query retrieves the final change in category (and the change in title). If I change the title and the category together, I see the category and title change right away.I’m using PDO to query the database directly not
wp_query()
.If anyone has any ideas of how to get the updated values right away, that would be great.
- The topic ‘`save_post` action is triggered before term_relationships is updated’ is closed to new replies.