New answers tagged


Use global $post at the top of the page just before the function start global $post;


The solution is using added_post_meta and updated_post_meta hook . Here is the working code . add_action( 'added_post_meta', 'add_custom_field_automatically', 10, 4 ); add_action( 'updated_post_meta', 'add_custom_field_automatically', 10, 4 ); function add_custom_field_automatically( $meta_id, $post_id, $meta_key, $meta_value ) { if ( '_my_meta_key' ...


A var_dump() in save_post action doesn't display any information on the screen. Well, it does only when you are on "Add new" screen. This is due the different sequence of actions that follow when creating a new post or when editing it. When you click on "publish" or "update" button, there is a request, the post is saved, save_post action is triggered and ...


A more reliable way of checking is to get $_POST['original_publish'], as that will return 'Publish' on first publishing it, and 'Update' on updating it.


One approach is to use get_post_status() According to the codex 'publish' - A published post or page 'pending' - post is pending review 'draft' - a post in draft status 'auto-draft' - a newly created post, with no content 'future' - a post to publish in the future 'private' - not visible to ...

Top 50 recent answers are included