Custom Fields
Re-Envisioned
Support Meta Box Show Hide (Javascript) Only show meta box on page with template named this-template.php

  • Creator
    Topic
  • #11263
    Resolved Philip 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' );
Viewing 2 replies - 1 through 2 (of 2 total)
  • Author
    Replies
  • #11265
    Anh 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 Lewis
    Participant

    Fantastic, thank you!

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