New answers tagged

-1

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


2

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' ...


1

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 ...


-1

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.


0

One approach is to use get_post_status() According to the codex http://codex.wordpress.org/Function_Reference/get_post_status '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