What for is the table “wp_commentmeta” exactly?

That table is essentially the same as for all of the other “meta” tables in the WordPress architecture. It holds misc. bits of extra, usually optional, information about the associated post, user, or in this case comment.

You can store whatever information you need to add to a comment– perhaps a plugin wants to implement “abuse” flags, or comment upvotes. It can really be just about anything.

This information would not go in the comments table because it is usually optional and additional, and has no predefined meaning. How many extra columns would you put in the comments table “just in case”? See what I mean.

You can see an example of use in the Codex entry for add_comment_meta.

function add_custom_comment_field( $comment_id ) {

   add_comment_meta( $comment_id, 'my_custom_comment_field', $_POST['my_custom_comment_field'] );
}
add_action( 'comment_post', 'add_custom_comment_field' );

Leave a Comment