Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to display comment's meta fields value in admin comment section?

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 ?

like image 736
Suman Biswas Avatar asked Dec 20 '22 13:12

Suman Biswas


1 Answers

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'] ) );
}
like image 186
Mrinmoy Majee Avatar answered May 25 '23 02:05

Mrinmoy Majee