Custom Fields
Re-Envisioned
Support MB Admin Columns No Admin Columns Showing

  • Creator
    Topic
  • #15302
    Resolved SLG 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;
        }
Viewing 3 replies - 11 through 13 (of 13 total)
  • Author
    Replies
  • #18188
    Anh 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 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.

Viewing 3 replies - 11 through 13 (of 13 total)
  • You must be logged in to reply to this topic.

Newsletter

Subscribe to our newsletter to receive news and tutorials for Meta Box and WordPress.


grid gear info copy caret-up caret-down trash