WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

The value is not updated when using the following code:

add_action( 'save_post', 'updatethumb' );

function updatethumb( $post_id ) {

    //verify post is not a revision
    if ( !wp_is_post_revision( $post_id ) ) {

        //$thumb = get_post_meta(get_the_ID(), 'thumb', false);
        $ft=get_post_meta(get_the_ID(), 'thumb', true);
        //echo '<script>alert("'.$ft.'")</script>';
        update_post_meta(get_the_ID(), 'thumb', 'testxxx'); 

    }

}

Why is that?

share|improve this question
1  
Why do you do this? get_the_ID does only work (as expected) within the Loop. You already have the post ID given in $post_id... – tfrommen Apr 22 '13 at 17:14

I'm not quite sure about what you want to do...
Maybe it's this:

add_action('save_post', 'update_thumb');

function update_thumb($post_id) {

    //verify post is not a revision
    if (! wp_is_post_revision($post_id)) {

        $new_value = 'testxxx';
        update_post_meta($post_id, 'thumb', $new_value); 

    }

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