How to make MB Group work with better-include.php

Support MB Group How to make MB Group work with better-include.php

Viewing 11 posts - 1 through 11 (of 11 total)
  • Author
    Posts
  • #510
    oquezadaoquezada
    Participant

    How 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 )
    	),
    );
    #519
    Anh TranAnh Tran
    Keymaster

    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.

    #522
    oquezadaoquezada
    Participant

    So is there a way to add conditions to show/hide "Group extension" for a specific page?

    #525
    Anh TranAnh Tran
    Keymaster

    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

    #542
    oquezadaoquezada
    Participant

    do you have an example of how to code this, so i can get an idea to accomplish this?

    #545
    Anh TranAnh Tran
    Keymaster

    No problem, it's quite straight forward. Try this code:

    https://gist.github.com/rilwis/423be7e4c38d14c09642

    #552
    oquezadaoquezada
    Participant

    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.

    https://ghostbin.com/paste/pejda

    #558
    Anh TranAnh Tran
    Keymaster

    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 MB Include Exclude extension, which is tested with Group extension.

    #565
    oquezadaoquezada
    Participant

    Ok, 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?

    #566
    Anh TranAnh Tran
    Keymaster

    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.

    #586
    oquezadaoquezada
    Participant

    Awesome it works with the MB Include Exclude extension, thanks!!!!

Viewing 11 posts - 1 through 11 (of 11 total)
  • The topic ‘How to make MB Group work with better-include.php’ is closed to new replies.