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 am trying to find reference for comment_post to insert custom data to custom table when comment post.

I want to insert below things to my custom table

  1. Comment's Post ID
  2. Custom content (which will done with custom query)

Can anyone please help me to do this?

share|improve this question

3 Answers 3

I have done this using comment_post action hook. Here is the answer if anyone need in future.

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'
        )

    );    

}
share|improve this answer

Your question is not very clear, but I think you are looking for the wp_insert_comment hook or one of the comment transitions hooks. Your question doesn't allow for a more detailed answer. There just isn't enough information.

function insert_comment_extra_wpse_85096($cid) {
  // $cid is your comment ID
}
add_action('wp_insert_comment','insert_comment_extra_wpse_85096');

See Also: http://codex.wordpress.org/Function_Reference/wp_transition_comment_status

share|improve this answer
    
I am really sorry for confusion and thanks a lot for your reply. However I wanted to add some custom data into the custom table when new comment post. I have done it using comment_post action hook. Adding as an answer. Thank you very much for your instant help. –  pixelngrain Feb 8 '13 at 17:05

Not sure what you're after but this is how you would get the content of a newly posted comment

add_action( 'comment_post', 'my_comment_callback' );
function my_comment_callback($id) {
    $comment = get_comments(array(
        'ID' => $id
    ));

    // $content is the actual text the user posted
    $content = $comment->comment_content;
}

Is that what you're looking for?

share|improve this answer
    
Please see my comment in s_ha_dum answer. Thank you very much for your instant help. –  pixelngrain Feb 8 '13 at 17:05
    
@pixelngrain ... If you used comment_post you should select this as the solution. –  s_ha_dum Feb 8 '13 at 17:07
    
which as the solution? your answer or my answer? Confused to understand. –  pixelngrain Feb 8 '13 at 17:24

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.