I've added an attachment field to my comment form. It stores the files on Amazon AWS and writes the URL, user ID, post ID, and a few other things to a custom table. I'm having some difficulty getting the comment ID in order to properly associate the attachment with the comment. Is there a good way to get the comment ID as it is being written?

I've looked over the documentation and cant seem to find anything that would get my comment ID on submit.


1 Answer 1


You can hook comment_post and add your logic with the comment id

// Save the data along with comment id
add_action( 'comment_post', 'wti_save_comment_data' );

function wti_save_comment_data( $comment_id ) {
    // Use the comment id and add your logic
  • I've got to rework some of my attachment script but this was exactly what I was looking for. Thanks!
    – Bms85smb
    Commented Dec 8, 2013 at 21:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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