I'm trying to add custom fields on post publish with this code which I added to my functions.php :
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);
}
}
This code should work but it doesn't ? I updated field and custom value but custom fields are never created.Why ?