Support MB Admin Columns How to show up the custom column in grouped meta Reply To: How to show up the custom column in grouped meta

#9444
downloadtakydownloadtaky
Participant

Actually I managed to show it like this, this is in functions.php:

/**
     * Registra admin columns Nuovo METODO
     */
    add_action( 'admin_init', 'et2018_add_custom_columns', 20 );
    function et2018_add_custom_columns() {
        require_once get_template_directory() . '/template-parts/admin/customcolumn-nuovo.php';
        new et2018_Custom_Admin_Columns( 'post', array() );
    }

This is the file I require:

<?php
    /**
     *
     * TODO Inserire codice per le colonne
     */
    class et2018_Custom_Admin_Columns extends MB_Admin_Columns_Post {
        public function columns( $columns ) {
            $columns  = parent::columns( $columns );
            $position = '';
            $target   = '';
            $this->add( $columns, 'column_id', 'Column Title', $position, $target );
            // Add more if you want
            return $columns;
        }
        public function show( $column, $post_id ) {
            switch ( $column ) {
                case 'column_id';
                    global $post;
                    $passaggiocantina = get_post_meta( $post->ID, 'gruppo_cantina', true );
                    if ( isset( $passaggiocantina['et2018-quantita_birra'] ) ) {
                        $quantita = $passaggiocantina['et2018-quantita_birra'];
                        foreach ($quantita as $quanto){echo $quanto.'-';}
                    };
                    break;
                // More columns
            }
        }
    }

Actually it works, is it the right way or there is a better one?