Support Forum
Support › Meta Box Group › How to make Meta Box Group work with better-include.php
How does one get to use Meta Box Group or Meta Box Tabs with better-include.php
global $meta_boxes;
$meta_boxes = array();
$meta_boxes[] = array(
'title' => __( 'Meta Box Title', 'meta-box' ),
'fields' => array(
array(
'name' => __( 'Your images', 'meta-box' ),
'id' => "{$prefix}img",
'type' => 'plupload_image',
),
),
'only_on' => array(
'id' => array( 1, 2 ),
// 'slug' => array( 'news', 'blog' ),
'template' => array( 'fullwidth.php', 'simple.php' ),
'parent' => array( 10 )
),
);
The better-include.php
only add conditions to show/hide whole meta box for a specific page, so it doesn't affect Group extension. Just define groups as normally, nothing changed.
So is there a way to add conditions to show/hide "Group extension" for a specific page?
I think there is a misunderstanding here:
- The Group extension is just one kind of field (special one), it acts exactly like other field type like text
, file
, etc.
- The techniques to show/hide meta boxes are applied for meta boxes only, not for fields, so they're not applied to groups.
But you can do a tricky way like this to achieve what you want:
- Create a meta box
- In that meta box, define only 1 group and put all fields under this group
- Use techniques above to hide whole meta box
Because this meta box contains only 1 group, show/hide this meta box actually show/hide this group.
Hope that helps. If you need anything, please let me know.
Thanks
do you have an example of how to code this, so i can get an idea to accomplish this?
No problem, it's quite straight forward. Try this code:
That's what I did, but apparently it seems not to be working for the Group/Tabs, it display on very page and I only want it to appear on the page templates that use "page-homepage.php". This is what i have coded.
Unfortunately the better-include.php
method uses old way to register meta boxes (via admin_init
hook). This way still works, but you can not use it with rwmb_meta_boxes
filter, e.g. if you register meta boxes with rwmb_meta_boxes
filter, you can't use better-include.php
method.
I'd suggest you use only global $meta_boxes
variable to register meta boxes, and remove code to register meta boxes via rwmb_meta_boxes
filter.
A better solution is using Meta Box Include Exclude extension, which is tested with Group extension.
Ok, if I buy the Meta Box Include Exclude extension, which is tested with Group extension. Do you have a example how to go about use it with Group and Tab extension to display it only on particulate Page Templates?
The example is well-written in the extension documentation. All you need is just add include
or exclude
parameter to meta box definition, no need to add custom function for checking like better-include demo.
Awesome it works with the Meta Box Include Exclude extension, thanks!!!!