This is a followup to my question about programmatically adding wordpress categories based on post content.
Which hook (or hooks) are most appropriate for use in a function or plugin that requires access to the content of a post seeks to run code at the time that post is committed to the database?
The former question led to the suggestion of using the edit_post hook. However my reading makes me wonder if I should use publish_post or save_post instead, or, indeed, if there is an even better option out there that I am not considering.
What, exactly, is the difference between these three hooks? If I want something to run at the time a post is made AND at the time any edits are made, is there one of these that encompasses both events, or do I need to tie in to multiple hooks?
save_post
is the most reliable single method that you’re looking for. More details here: Detailspublish_post
does not fire if you save a post as a draft or schedule it to be published later. Detailsedit_post
is not fired in the case where a new post is created. However,edit_post
is fired at many other times like when a new comment is created/edited etc. Details