What for is the table “wp_commentmeta” exactly?

I have been reading about the Database Description of WordPress. I haven’t understood the meaning to the use of the table wp_commentmeta.

The documentation says:

Read More

Each comment features information called the meta data and it is stored in the wp_commentmeta.

I have a fair idea of what meta-data is. I know how the table wp_postmeta stores custom field, for example. But in the case of the comments, I don’t understand:

  • What kind of information would go in this table?

  • Why wouldn’t it be in the same wp_comments table?

  • What is a practical example of how someone would use it, so that I could test it out and have a more graphic idea of how it works?

Related posts

2 comments

  1. 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' );
    
  2. This can be used, mainly by plugins, to add some additional information to a comment. By having one generic table you don’t need to add columns to wp_comment for every additional piece of data.

    E.g. a plugin could add a rating to each comment and store that value in wp_commentmeta.

Comments are closed.