Support Forum
Support › MB Admin Columns › No Admin Columns ShowingResolved
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;
}
I know this is a stupid question, but have you activated the MB Admin Columns extension? Some users forget to do this.
It's being loaded as an MU plugin. I'll try moving it to the normal plugin folder.
I just tried it as a normal plugin, I am getting the same issue.
Is there any further debug information you need on this?
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
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.
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);
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.
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.
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.
@Aart: do you have fields with the same IDs?
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.
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.
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!