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?


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?

  • Please see my comment in s_ha_dum answer. Thank you very much for your instant help. 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. Feb 8 '13 at 17:24

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

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

  • 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. Feb 8 '13 at 17:05

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->prefix. 'my_medias',
            'post_id' => $post_id,
            'image_name' => 'trial-image1',
            'status' => 1




Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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