How to show up the custom column in grouped meta

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

Viewing 9 posts - 1 through 9 (of 9 total)
  • Author
    Posts
  • #9443
    downloadtakydownloadtaky
    Participant

    Hi,
    I've read here: https://docs.metabox.io/extensions/mb-admin-columns/
    That if I would like to add a custom column (after activating the plugin and all his dependencies) the only thing I have to do is to add 'admin_columns' => 'after title',
    obviusly this works only if I haven't grouped metaboxes.
    How to achieve the same thing with grouped meta?
    These are my custom meta:
    https://pastebin.com/bzTtiMjG

    Let's imagine I would like to show the value taken by this:

    array(
                            'id'          => $prefix.'quantita_birra',
                            'type'        => 'text',
                            'name'        => 'Quantità birra',
                            'desc'        => 'Quante ne hai in magazzino o cella?',
                            'placeholder' => 'Quante ne hai?',
                            'clone'      => 1,
                            'sort_clone' => true,
                            'step' => '0.1',
                            'admin_columns' => 'after title',
                        ),

    that is inside gruppo_cantina

    Thank you very much.

    #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?

    #9445
    downloadtakydownloadtaky
    Participant

    How can I make it sortable and how can I use quick edit to modify it?

    #9446
    downloadtakydownloadtaky
    Participant

    Is there also a way to correlate values?
    My metas are in Italian, anyway what I am working is something like an Inventory for beers in my cellar (I am a pub owner).
    Cantina is the italian word for cellar.
    Let's imagine we have a beer named (nome_birra): Cantillon Gueuze .
    This beer can have 3 different sizes (formato_birra):
    37.5cl / 75cl / Magnum
    But it can also be from a different batch (annata_birra) so we can have as an example:
    37.5cl -2013/2015
    75cl - 2017
    Magnum - 2014
    So I can have different amount of bottles for each size and batch (quantita_birra):
    37.5cl - 2013 :1
    37.5cl - 2015 :3
    75cl - 2017:5
    Magnum - 2014: 2
    And each combination has obviously a differente price (prezzo_birra).
    So, how can I create such a multidimentional array and then show the values in the custom column?

    #9466
    Anh TranAnh Tran
    Keymaster

    Hello,

    Regarding the code to show a sub-field inside a group, your code is correct and that is a nice approach. I guest that's the best way to do it.

    Sorting seems not to be doable for group values, unfortunately. The quick edit is not available at the moment, neither (we haven't done that for normal fields as well).

    Regrading your data, I think you can just create a group called variation (a combination, you can find any better name) and it has 3 sub-fields:

    • Size: can be a select field if number of sizes are limited
    • Batch: a text field or select field (if you have predefined batches)
    • Amount of bottles: number field
    • Price

    Then you can show those info in the admin columns in a similar way that you already did above (with similar code).

    #9470
    downloadtakydownloadtaky
    Participant

    Can I clone a group?
    var SIZE has defined values (37.5cl/50cl/75cl/magnum/keg)
    but inside same sizes I can have different batches and these aren't fixed values (we are talking about a huge craft beer cellar where some beers are from 1999/2000/2001/2002....)
    Obviously any combination has a different price and availability.
    So if I was able to do something like a multidimensional loop (pseudo code ahead):
    foreach ($size as $sizes){foreach ($37 as $37s){2017=10€=10;2015=12€=5;2013=15€=3};};
    It would help a lot, maybe a conditional 'clone' or something like that?

    #9471
    downloadtakydownloadtaky
    Participant

    Ok, now I have nested, clonable, groups, let's try to see if it works

    #9472
    downloadtakydownloadtaky
    Participant

    This is the code I used while the date where in string (before all the group madness) to retrieve the meta_key_value.
    It echoes the value in a new column inside edit screen and also let me modify It using quick edit.
    The problem is that it can't work with my actual configuration.
    Anyway, here is my code:
    https://pastebin.com/ZqvmHcye

    And this is the code I use to generate metaboxes. I've added a couple of comments to try to explain what I would like to extract and being able to modify.
    https://pastebin.com/4BgTUcRM

    Do you think is there a way to rearrange old code to be compatible with the new one?
    Thank you.

    #9499
    Anh TranAnh Tran
    Keymaster

    I'm not sure about the quick edit for groups. It's kind of custom output + JavaScript. As long as you format the submitted data in correct way (e.g. array of sub-fields values), it might work. So, please be very careful about the data, or you might lost them.

Viewing 9 posts - 1 through 9 (of 9 total)
  • The topic ‘How to show up the custom column in grouped meta’ is closed to new replies.