I’d like to run a custom query using some meta data whenever a post is updated or published.
Is there something I can put in functions.php to fire when those events occur?
I’d like to run a custom query using some meta data whenever a post is updated or published.
Is there something I can put in functions.php to fire when those events occur?
You must be logged in to post a comment.
The
save_post
action fires When a post is updated and/or published — including when a new post is inserted.If you want your functions to fire only when a post is being edited, you can hook into
edit_post
.If you want it to fire when a post is moved from draft to publish you can hook into
transition_post_status
.There are several actions you can use. For example:
save_post
edit_post
publish_post
While lesser-used, there are also post-status transition hooks.
the edit_post hook is probably the best hook… as it fires whenever a post/page is published or updated. save_post is another viable option… maybe better if you don’t need it to fire when comments are updated.
http://codex.wordpress.org/Plugin_API/Action_Reference
the save_post page in the codex has an example of a function that fires whenever a post is saved:
http://codex.wordpress.org/Plugin_API/Action_Reference/save_post
If you want to perform an action when any custom post update/save –