How to make MB Group work with better-include.php
- This topic has 10 replies, 2 voices, and was last updated 10 years, 1 month ago by
oquezada.
-
AuthorPosts
-
February 28, 2015 at 1:09 AM #510
oquezada
ParticipantHow does one get to use MB Group or MB 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 ) ), );
March 3, 2015 at 11:55 PM #519Anh Tran
KeymasterThe
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.March 4, 2015 at 1:00 AM #522oquezada
ParticipantSo is there a way to add conditions to show/hide "Group extension" for a specific page?
March 4, 2015 at 8:28 AM #525Anh Tran
KeymasterI 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 boxBecause 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
March 5, 2015 at 11:01 PM #542oquezada
Participantdo you have an example of how to code this, so i can get an idea to accomplish this?
March 6, 2015 at 11:37 AM #545Anh Tran
KeymasterNo problem, it's quite straight forward. Try this code:
March 7, 2015 at 1:53 AM #552oquezada
ParticipantThat'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.
March 7, 2015 at 10:26 PM #558Anh Tran
KeymasterUnfortunately the
better-include.php
method uses old way to register meta boxes (viaadmin_init
hook). This way still works, but you can not use it withrwmb_meta_boxes
filter, e.g. if you register meta boxes withrwmb_meta_boxes
filter, you can't usebetter-include.php
method.I'd suggest you use only global
$meta_boxes
variable to register meta boxes, and remove code to register meta boxes viarwmb_meta_boxes
filter.A better solution is using MB Include Exclude extension, which is tested with Group extension.
March 10, 2015 at 11:17 AM #565oquezada
ParticipantOk, if I buy the MB 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?
March 10, 2015 at 3:11 PM #566Anh Tran
KeymasterThe example is well-written in the extension documentation. All you need is just add
include
orexclude
parameter to meta box definition, no need to add custom function for checking like better-include demo.March 12, 2015 at 1:24 AM #586oquezada
ParticipantAwesome it works with the MB Include Exclude extension, thanks!!!!
-
AuthorPosts
- The topic ‘How to make MB Group work with better-include.php’ is closed to new replies.