Add custom field automatically when post or page is publish

Go to source

snippet :  PHPcopy
add_action('publish_page', 'add_custom_field_automatically');
add_action('publish_post'. 'add_custom_field_automatically');
function add_custom_field_automatically($post_ID) {
    global $wpdb;
    if(!wp_is_post_revision($post_ID)) {
        add_post_meta($post_ID, 'FIELD_NAME', 'CUSTOM VALUE', true);
    }
}


Add custom field automatically when post or page is publish is a post from: wpsnipp.comWordPress Snippets, Code, Hacks, 590+ for your theme, blog
which is not allowed to be copied on other sites.”

Share this post.


Add custom field automatically when post or page is publish“>Facebook | Add custom field automatically when post or page is publish“>StumbleUpon | Add custom field automatically when post or page is publish“>Delicious | Add custom field automatically when post or page is publish @wpsnipp”>Tweet It |