Action hook ‘save_post’ triggered when deleting posts

It’s probably easiest to just check the post status within your function. Untested: add_action( ‘save_post’, ‘rewrite_post’, 10, 2 ); function rewrite_post( $post_id ) { if ( ‘trash’ != get_post_status( $post_id ) ) { remove_action( ‘save_post’, ‘rewrite_post’ ); $title = preg_replace( ‘/\_/’, ‘ ‘, get_the_title( $post_id ) ); $my_post = array( ); $my_post[‘ID’] = $post_id; $my_post[‘post_title’] … Read more

$update is always true in save_post

So appreciate this is a bit late but I was having the exact same issue, the $update parameter is almost completely useless if you want to check whether it is a new post or not. The way I got around this was to compare the $post->post_date with $post->post_modified. Full code snippet below. add_action( ‘save_post’, ‘save_post_callback’, … Read more

Unable to prevent function using save_post firing twice

First, you can use this hook to target only one custom type: https://developer.wordpress.org/reference/hooks/save_post_post-post_type/ This hook (and save_post) is called the first time when you click on “new …” and then the hook is called with $update = FALSE. Then to send e-mail only when the object is updated, you can test $update like this: const … Read more

trigger save_post event programmatically

It’s wp_insert_post() vs. wp_update_post() – where update will ultimately also call: return wp_insert_post( $postarr, $wp_error, $fire_after_hooks ); The term “once” implies that it is being fired “afterwards”. /** * Fires once a post has been saved. * * @since 1.5.0 * * @param int $post_ID Post ID. * @param WP_Post $post Post object. * @param … Read more

How do the ‘tag’ and ‘category’ (default) taxonomies do ‘save_post’ action?

It’s informative to check out the /wp-admin/post.php file, that contains the edit_post() function that calls wp_update_post(), which is a wp_insert_post() wrapper. Here’s a skeleton for saving the assigned category terms: /** * Saving assigned category terms (skeleton) */ add_action( ‘admin_action_editpost’, function() { add_filter( ‘wp_insert_post_data’, function( $data, $parr ) { add_action( ‘save_post_post’, function( $post_ID, $post ) … Read more

Return $post_id when DOING_AUTOSAVE?

The ‘save_post’ action was added to core in 2.0, and has always been an action. Looking through the current autosave procedures, it doesn’t appear to call the ‘save_post’ action directly at any time. So the short answer is, no. There is no reason, and has never been any reason, to return any value on this … Read more

Set custom messages for post update/save

http://codex.wordpress.org/Function_Reference/register_post_type example: //add filter to ensure the text Book, or book, is displayed when user updates a book add_filter(‘post_updated_messages’, ‘codex_book_updated_messages’); function codex_book_updated_messages( $messages ) { global $post, $post_ID; $messages[‘book’] = array( 0 => ”, // Unused. Messages start at index 1. 1 => sprintf( __(‘Book updated. <a href=”https://wordpress.stackexchange.com/questions/17885/%s”>View book</a>’), esc_url( get_permalink($post_ID) ) ), 2 => … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)