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

Get Post ID with insert/edit link

Not an exact answer to your question (hooking into the insert/edit link functionality), but possibly an alternate method that can achieve the same goal (inputting a permalink, outputting a Post ID): https://codex.wordpress.org/Function_Reference/url_to_postid

save_post only saves meta data on second save

Did you try removing the IF statements and use save_post hook instead of save_post_listing to see if an IF statement is blocking the wp_set_post_terms? Also try wp_set_object_terms instead of wp_set_post_terms. Furthermore, if you can make sure it has to do with the if(get_post_meta($post_id, ‘wpcf-proprty_online’, true) == ‘y’) statement, then this post_meta has not been updated …

Read more

Return code from save_post action?

Actions should not return anything, and action hooks are not built to do anything with a returned value. (That is what filters are for.) If you look at the source for that particular hook, you can see that even if you return something nothing happens. Whatever you return isn’t captured. It vanishes from the code. …

Read more