Timeline for what is correct way to hook when update post
Current License: CC BY-SA 3.0
7 events
when toggle format | what | by | license | comment | |
---|---|---|---|---|---|
Nov 13, 2018 at 9:18 | comment | added | lowtechsun | Thank you for getting back to me. Just found out about this yesterday and thought the concept of this is confusing. Meaning first I open the page to add a new post. At this stage I thought I have not already created a post. Only once I hit Publish I would think the new post is created. Taking this further I hope WP does delete the auto-draft post if I hit Add New but then leave the page without hitting Publish? | |
Nov 13, 2018 at 9:14 | comment | added | gmazzap | @lowtechsun Like it is said in the A, the hooks are fired every time a post is updated, i.e. saved in DB. When you hit "Add New", close to page loading, WP creates a draft post stored in DB so he hooks are fired. | |
Nov 12, 2018 at 17:52 | comment | added | lowtechsun |
I think that the 'save_post' action hook is also fired when hitting Add New (Post, Page, CPT) in the dashboard. To see yourself just run this code. function save_post_test( $post_id, $post, $update ) { print ' post_id : '; var_export( $post_id ); print ' post : '; var_export( $post ); print ' update : '; var_export( $update ); wp_die( 'save_post hook runs when you click Add New..' ); } add_action( 'save_post', 'save_post_test', 10, 3 ); Why does the 'save_post' action run on Add New instead of on Publish? To make the auto-draft post I suppose.
|
|
Apr 13, 2017 at 12:37 | history | edited | CommunityBot |
replaced http://wordpress.stackexchange.com/ with https://wordpress.stackexchange.com/
|
|
Nov 28, 2014 at 11:42 | history | edited | kaiser | CC BY-SA 3.0 |
added missing hook
|
Feb 15, 2014 at 1:36 | vote | accept | rusly | ||
Feb 14, 2014 at 17:08 | history | answered | gmazzap | CC BY-SA 3.0 |