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

I am adding custom data to custom table while author posting a comment. Please find my code in my own answer here http://wordpress.stackexchange.com/a/85109/9821

add_action('comment_post', 'insert_gallery');
function insert_gallery() {

    global $wpdb, $post;
    $post_id = $post->ID;

    $wpdb->insert(
        $wpdb->prefix. 'my_medias',
        array(
            'post_id' => $post_id,
            'image_name' => 'trial-image1',
            'status' => 1
        ),            
        array(
            '%d',
            '%s',
            '%d'
        )            
    );            
}

Now I want to add one more column of 'author_ID' and not able to get the comment author id on the fly.

Can anyone help me to get comment author id on the fly and insert into custom table column author_ID

share|improve this question

Ah! It was so simple :P

Just using WP built in function

get_current_user_id( )

and all done. Thanks a lot.

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.