Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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 ?

share|improve this question
1  
You have a period in the second add_action –  AlxVallejo Aug 23 '12 at 14:07
    
Thank you so much ! :)))) It is fixed –  Rorkkkk Aug 23 '12 at 14:46
1  
@AlxVallejo please post your comment as an answer so it can be accepted to prevent this question from appearing as unanswered. –  Milo Aug 23 '12 at 15:11

1 Answer 1

up vote 0 down vote accepted
add_action('publish_post'. 'add_custom_field_automatically');

You have a period in the second add_action. This should be a comma :)

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.