I have added an extra field in wordpress comment form for user age. I have added the field like this way :
add_filter('comment_form_default_fields','add_comment_fields');
function add_comment_fields($fields) {
$fields['location'] = '<p class="comment-form-location"><label for="location">' . __( Location ) . '</label>' .
'<input id="location" name="location" type="text" size="30" /></p>';
return $fields;
}
And also I have saved the meta value in comment meta table by using 'comment_post' action. Now I have to display this comment meta value in admin comment section. How can I do this ?
Try bellow code, hope you will able to see your extra field in admin section(Here i use age as meta key).
add_action( 'add_meta_boxes_comment', 'comment_add_meta_box' );
function comment_add_meta_box()
{
add_meta_box( 'my-comment-title', __( 'Your field title' ), 'comment_meta_box_age', 'comment', 'normal', 'high' );
}
function comment_meta_box_age( $comment )
{
$title = get_comment_meta( $comment->comment_ID, 'age', true );
?>
<p>
<label for="age"><?php _e( 'Your label Name' ); ?></label>;
<input type="text" name="age" value="<?php echo esc_attr( $title ); ?>" class="widefat" />
</p>
<?php
}
add_action( 'edit_comment', 'comment_edit_function' );
function comment_edit_function( $comment_id )
{
if( isset( $_POST['age'] ) )
update_comment_meta( $comment_id, 'age', esc_attr( $_POST['age'] ) );
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With