Only show meta box on page with template named this-template.php

Support MB Show Hide Only show meta box on page with template named this-template.phpResolved

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #11263
    Philip LewisPhilip Lewis
    Participant

    Just bought the plugin, what do we need to do to hide this metabox for every page except those with page template this-template.php

    function testmeta( $meta_boxes ) {
        $prefix = 'swed-';
    
        $meta_boxes[] = array(
            'id' => 'vendoroptions',
            'title' => esc_html__( 'Vendors', 'metabox-online-generator' ),
            'post_types' => array( 'page' ),
            'context' => 'after_title',
            'priority' => 'high',
            'autosave' => false,
            'fields' => array(
                array(
                    'id' => $prefix . 'mainphoto',
                    'type' => 'image_advanced',
                    'name' => esc_html__( 'Main Photo', 'metabox-online-generator' ),
                ),
                array(
                    'id' => $prefix . 'appt-2',
                    'type' => 'wysiwyg',
                    'name' => esc_html__( 'Appointment', 'metabox-online-generator' ),
                ),
                array(
                    'id' => $prefix . 'logo',
                    'type' => 'image_advanced',
                    'name' => esc_html__( 'Vendor Logo', 'metabox-online-generator' ),
                ),
                array(
                    'id' => $prefix . 'desc',
                    'name' => esc_html__( 'Description', 'metabox-online-generator' ),
                    'type' => 'wysiwyg',
                ),
            ),
        );
    
        return $meta_boxes;
    }
    add_filter( 'rwmb_meta_boxes', 'testmeta' );
    #11265
    Anh TranAnh Tran
    Keymaster

    Hi Philip,

    Please add show parameter to the meta box settings as follows:

    function testmeta( $meta_boxes ) {
        $prefix = 'swed-';
    
        $meta_boxes[] = array(
            'id' => 'vendoroptions',
            'title' => esc_html__( 'Vendors', 'metabox-online-generator' ),
            'post_types' => array( 'page' ),
            'context' => 'after_title',
            'priority' => 'high',
            'autosave' => false,
            'show' => array(
                'template' => array( 'this-template.php' ),
            ),
            'fields' => array(),
       );
       return $meta_boxes;
    } );

    For more details, please see the documentation.

    #11272
    Philip LewisPhilip Lewis
    Participant

    Fantastic, thank you!

Viewing 3 posts - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.