No Admin Columns Showing

Support MB Admin Columns No Admin Columns ShowingResolved

Viewing 15 posts - 1 through 15 (of 16 total)
  • Author
    Posts
  • #15302
    SLG MarketingSLG Marketing
    Participant

    I've tried adding some admin columns to a CPT but they won't output at all. What am I doing wrong?

     public function generateMetaBox($meta_boxes){
            // General
            $meta_boxes[]=array(
                'id'=>'general',
                'title'=>'General Person Settings',
                'post_types' => 'people',
                'context'    => 'normal',
                'priority'   => 'high',
                'fields'=> array(
                    array(
                        'name'  =>  'Job Title',
                        'id'    =>  'people_jobtitle',
                        'type'  =>  'text',
                        'desc'=>'TODO: help text',
                        'admin_columns' => 'after title'
                    ),
                    array(
                        'name'=>'Year Joined',
                        'id'=>'people_yearjoined',
                        'desc'=>'TODO: help text',
                        'type'=>'number',
                        'min'   =>  1980,
                        'max'   =>  date('Y'),
                        'admin_columns' => true,
                    ),
                )
            );
    
            return $meta_boxes;
        }
    #15307
    Anh TranAnh Tran
    Keymaster

    I know this is a stupid question, but have you activated the MB Admin Columns extension? Some users forget to do this.

    #15311
    SLG MarketingSLG Marketing
    Participant

    It's being loaded as an MU plugin. I'll try moving it to the normal plugin folder.

    #15312
    SLG MarketingSLG Marketing
    Participant

    I just tried it as a normal plugin, I am getting the same issue.

    #15406
    SLG MarketingSLG Marketing
    Participant

    Is there any further debug information you need on this?

    #18062

    Did anyone ever find anything on this issue?
    I'm having similar issues at the moment, and it looks like it's related to the id in the main array ('general' in this example).
    On my setup it seems that only fields from an array where the 'id' is equal to the post-type slug are presented in the admin columns. But this is something recent, because I know quite certain that the field showed up a few months ago.

    Any thoughts?

    Best,

    AJ

    #18064
    SLG MarketingSLG Marketing
    Participant

    Hi

    I didn't get any feedback from the devs which was a little disappointing.

    My own research indicates that it is caused by the order that custom post types are loaded. I haven't looked at this for ages so I'll spin up a test site and do some more digging.

    #18066
    SLG MarketingSLG Marketing
    Participant

    I have figured this out, you need to have an execution order greater than the default of 10 on the metabox rwmb_meta_boxes filter.

    add_filter( 'rwmb_meta_boxes', [$this,'generateMetaBox']);
    

    Becomes

    add_filter( 'rwmb_meta_boxes', [$this,'generateMetaBox'],20);
    
    #18091
    Anh TranAnh Tran
    Keymaster

    Hi guys, sorry for not following up the thread. I think the solution above should work. Please let me know if you have any trouble with that.

    #18177

    Hi,

    the order definitely does influence the appearance of the admin columns, but only the highest one remains visible. Our website had multiple calls to
    add_filter( 'rwmb_meta_boxes', function($metabox){$metabox[]=[....]}, 20);
    (one for each post-type)

    If I add both
    add_filter( 'rwmb_meta_boxes', function($metabox){$metabox[]=[....]}, 20);
    and
    add_filter( 'rwmb_meta_boxes', function($metabox){$metabox[]=[....]}, 21);
    all fields function properly, except the admin columns: only the admin columns in the highest one do appear.

    #18179
    SLG MarketingSLG Marketing
    Participant

    What order are you loading in your CPTs?

    We load ours from MU plugins which has a higher execution order than ones in the theme or the normal plugin folder.

    #18188
    Anh TranAnh Tran
    Keymaster

    @Aart: do you have fields with the same IDs?

    #18257

    Sorry for the delay, yes, both fields and metaboxes appear with duplicate ID's.

    And that seems to be a way to solve this issue: different ID's for the metaboxes fixes the issue.

    Field ID's are still identical over multiple metabox-definitions, but that doesn't seem to matter, does it? It's because I use the same fields for different CPT's and I want to use separate classes (one per CPT) to define them. But in the templates, the field ID should ideally be identical.

    #18267
    Anh TranAnh Tran
    Keymaster

    You're right.

    Meta boxes' IDs must be unique as they're stored in a registry with ID as key.

    Fields for different post types might have the same IDs, as we also use post type as key in the field registry. Of course, unique is better.

    #29684
    PauPau
    Participant

    Hi,

    I know this thread is old, but I experienced the same behaviour and in my case it was an error from my part because when I was declaring the metaboxes I used the same id for all of them as

     $meta_boxes[]=array(
                'id'=>'general',
                'post_types'=>'people'

    If I set a different id for each metabox field group it works fine. According to the documentation the field group id should be unique, but I thought that since I only have one metabox field group for each CPT that won't be a problem. But it is.

    Hope this helps someone!

Viewing 15 posts - 1 through 15 (of 16 total)
  • You must be logged in to reply to this topic.