$conf, $runtime; function_exists('chdir') AND chdir(APP_PATH); $r = 'mysql' == $conf['cache']['type'] ? website_set('runtime', $runtime) : cache_set('runtime', $runtime); } function runtime_truncate() { global $conf; 'mysql' == $conf['cache']['type'] ? website_set('runtime', '') : cache_delete('runtime'); } register_shutdown_function('runtime_save'); ?>comments - What for is the table "wp_commentmeta" exactly?|Programmer puzzle solving
最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

comments - What for is the table "wp_commentmeta" exactly?

matteradmin8PV0评论

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:

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?

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:

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?

Share Improve this question edited Feb 19, 2014 at 0:00 Enrique Moreno Tent asked Feb 18, 2014 at 23:52 Enrique Moreno TentEnrique Moreno Tent 2771 gold badge3 silver badges11 bronze badges
Add a comment  | 

2 Answers 2

Reset to default 3

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

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.

Post a comment

comment list (0)

  1. No comments so far