Displaying a custom field in the list of comments in the backend using MB Admin

Support MB Admin Columns Displaying a custom field in the list of comments in the backend using MB Admin

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #36449
    MaxMax
    Participant

    How to use this code to display a custom field previously created in the comments list in the backend:

    add_action( 'admin_init', function() {
        class My_comment_Columns extends \MBAC\Post {
            public function columns( $columns ) {
                $columns  = parent::columns( $columns );
                $position = 'after';
                $target   = 'comments';
                $this->add( $columns, 'my_custom_field', 'my custom field', $position, $target );
                // Add more if you want
                return $columns;
            }
            public function show( $column, $post_id ) {
                switch ( $column ) {
                    case 'my_custom_field':
                        echo('???');
                        break;
                    // More columns
                }
            }
        }
    
        new My_comment_Columns( '???', array() );
    } );
    #36472
    Long NguyenLong Nguyen
    Moderator

    Hi Max,

    Currently, the plugin MB Admin Columns does not support adding columns in the comment table (admin area). I will inform the development team to consider supporting it in future updates.

    #36473
    MaxMax
    Participant

    It would be great. Moreover, there is already a solution - you just need to adapt it to your function. I did like this in my task:

    add_filter('manage_edit-comments_columns', function($columns)
    {
        $columns['custom_col_title'] = 'Archive id';
    
        return $columns;
    }, 10);
    
    add_action('manage_comments_custom_column', function($column, $comment_ID)
    {
        if($column == 'custom_col_title')
        {
            echo get_comment_meta( $comment_ID, 'archive_id_comment_m', true );
        }
    }, 10, 2);
Viewing 3 posts - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.