Custom Fields
Re-Envisioned
Support Meta Box Include Exclude Meta Box Not Showing Up

This topic contains 2 replies, has 2 voices, and was last updated by  tone4407 3 years, 7 months ago.

  • Creator
    Topic
  • #1595

    tone4407
    Participant

    Forgive me, I’m a newb.

    I have the Meta Box plugin and just purchased the Include/Exclude plugin so I can show the custom meta boxes on the home page only.

    Here is my code:

    <?php
    add_filter( 'rwmb_meta_boxes', 'meta_box_include_exclude_demo_register' );
    /**
     * Register meta boxes
     *
     * @param array $meta_boxes
     *
     * @return array
     */
    function meta_box_include_exclude_demo_register( $meta_boxes )
    {
        // 1st meta box
        $meta_boxes[] = array(
            // Meta box id, UNIQUE per meta box. Optional since 4.1.5
            'id'         => 'meta-decoy-101',
    
            // Meta box title - Will appear at the drag and drop handle bar. Required.
            'title'      => __( 'Decoy 101', 'meta-decoy-101' ),
    
            // Where the meta box appear: normal (default), advanced, side. Optional.
            'context'    => 'normal',
    
            // Order of meta box: high (default), low. Optional.
            'priority'   => 'high',
    
            // Auto save: true, false (default). Optional.
            'autosave'   => true,
    
            // Register this meta box for posts matched below conditions
            'include' => array(
                // List of page templates. Can be array or comma separated. Optional.
                'template' => array( 'page-home.php' ),
            ),
            // List of meta fields
            'fields'     => array(
                /// WYSIWYG/RICH TEXT EDITOR
                array(
                    // 'name'    => __( 'WYSIWYG / Rich Text Editor', 'your-prefix' ),
                    'id'      => "meta-decoy-101-content",
                    'type'    => 'wysiwyg',
                    // Set the 'raw' parameter to TRUE to prevent data being passed through wpautop() on save
                    'raw'     => false,
                    // Editor settings, see wp_editor() function: look4wp.com/wp_editor
                    'options' => array(
                        'textarea_rows' => 10,
                        'teeny'         => true,
                        'media_buttons' => false,
                    ),
                ),
            ),
        );
        return $meta_boxes;
    }
    /**
     * Manual check for including meta box
     * You can check ANY conditions here
     *
     * @param $meta_box
     *
     * @return bool
     */
    function manual_include( $meta_box )
    {
        if ( $meta_box['title'] == 'Include Meta Box' )
            return true;
        return false;
    }

    It’s not showing up when I go to Edit Page for the Home Page. The home page is set to use the page-home.php template.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Author
    Replies
  • #1601

    Anh Tran
    Keymaster

    Hi,

    I don’t see post_types parameter for the meta box. Please add this:

    'post_types' => 'page',
    'fields' => ... // Your fields here

    For more info about post_types, please check here.

    #1604

    tone4407
    Participant

    That did the trick. Thanks, Anh!

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

The topic ‘Meta Box Not Showing Up’ is closed to new replies.