Custom Fields
Re-Envisioned
Support Meta Box Group How to make Meta Box Group work with better-include.php

This topic contains 10 replies, has 2 voices, and was last updated by  oquezada 4 years, 5 months ago.

  • Creator
    Topic
  • #510

    oquezada
    Participant

    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 )
    	),
    );
Viewing 10 replies - 1 through 10 (of 10 total)
  • Author
    Replies
  • #519

    Anh 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

    oquezada
    Participant

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

    #525

    Anh 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

    oquezada
    Participant

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

    #545

    Anh Tran
    Keymaster

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

    #552

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

    #565

    oquezada
    Participant

    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?

    #566

    Anh 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

    oquezada
    Participant

    Awesome it works with the Meta Box Include Exclude extension, thanks!!!!

Viewing 10 replies - 1 through 10 (of 10 total)

The topic ‘How to make Meta Box Group work with better-include.php’ is closed to new replies.