Why not fire the save_post event?

The save_post action hook fires after a post is saved: every time, even for autosaves. If you look at the reference for save_post, you’ll see that the callback receives three parameters: the first is an integer $post_ID, the second is a WP_Post object $post, and the third is a boolean $update. None of the parameters … Read more

Clear cache on post of one type when something happens to post of other type

I suppose a quick and dirty way to achieve what you want is to clear the entire site cache, something like this: function clear_rocket_cache_on_post_save() { rocket_clean_domain(); } add_action( ‘save_post’, ‘clear_rocket_cache_on_post_save’ ); Otherwise you’ll need to do a query to get the matching post, something like this should work: function clear_rocket_cache_on_post_save( $post_id ) { // $result_id … Read more

save_post requiere at least one uploaded file to be published

I didn’t test this, but it should work: function check_post_attachments($post_id, $post){ if(empty(get_posts(array(‘post_type’ => ‘attachment’, ‘post_parent’ => $post_id)))){ $post[‘post_status’] = ‘draft’; wp_update_post($post); } } add_action(‘save_post’, ‘check_post_attachments’);

Why save_post_$(custom_post_type) is fired even if I am not already saving a post?

When you choose “Your CPT > Add New”, WP calls get_default_post_to_edit(), which actually creates an “empty” post (with ‘post_status’ => ‘auto-draft’) and then calls wp_insert_post(). This is what is causing your save_datasheet_meta() function to be called before you think it should. Hence, generally you should add some additional sanity checks to the beginning of any … Read more