No Admin Columns Showing
Support › MB Admin Columns › No Admin Columns ShowingResolved
- This topic has 15 replies, 4 voices, and was last updated 3 years, 8 months ago by
Pau.
-
AuthorPosts
-
July 9, 2019 at 10:48 PM #15302
SLG Marketing
ParticipantI'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; }
July 10, 2019 at 9:07 AM #15307Anh Tran
KeymasterI know this is a stupid question, but have you activated the MB Admin Columns extension? Some users forget to do this.
July 10, 2019 at 3:21 PM #15311SLG Marketing
ParticipantIt's being loaded as an MU plugin. I'll try moving it to the normal plugin folder.
July 10, 2019 at 3:35 PM #15312SLG Marketing
ParticipantI just tried it as a normal plugin, I am getting the same issue.
July 19, 2019 at 6:04 PM #15406SLG Marketing
ParticipantIs there any further debug information you need on this?
January 30, 2020 at 6:06 PM #18062Aart Jan van der Linden
ParticipantDid 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
January 30, 2020 at 8:02 PM #18064SLG Marketing
ParticipantHi
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.
January 31, 2020 at 12:02 AM #18066SLG Marketing
ParticipantI 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);
February 1, 2020 at 3:26 PM #18091Anh Tran
KeymasterHi 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.
February 6, 2020 at 6:00 PM #18177Aart Jan van der Linden
ParticipantHi,
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.February 7, 2020 at 12:21 AM #18179SLG Marketing
ParticipantWhat 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.
February 7, 2020 at 4:48 PM #18188Anh Tran
Keymaster@Aart: do you have fields with the same IDs?
February 13, 2020 at 5:54 PM #18257Aart Jan van der Linden
ParticipantSorry 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.
February 14, 2020 at 3:26 PM #18267Anh Tran
KeymasterYou'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.
July 25, 2021 at 4:16 PM #29684Pau
ParticipantHi,
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!
-
AuthorPosts
- You must be logged in to reply to this topic.