Metabox for page template disappears

Support MB Show Hide Metabox for page template disappearsResolved

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #17886
    mzykinmzykin
    Participant

    After upgrading MB and all extensions to the latest versions, I'm no longer able to set meta boxes for page templates successfully.

    With the code below, the metabox appears on all pages, briefly, then disappears. It also disappears on the page with the selected page template:

    
    function tmg_register_meta_boxes ( $meta_boxes ) {
        $meta_boxes[] = array (
            'title' => esc_html__( 'Home - Photo Spotlight', 'tmg' ),
            'id' => 'home-photo-spotlight',
            'post_types' => array(
               'page'
            ),
            'show' => array(
                'template' => 'page_home.php'
            ),
            'context' => 'after_title',
            'priority' => 'high',
            'fields' => array(
                array (
                    'id' => 'home-photo-spotlight-image',
                    'type' => 'single_image',
                    'name' => esc_html__( 'Photo Spotlight', 'tmg' ),
                    'desc' => esc_html__( 'This image appears next to the "Values" section.', 'tmg' ),
                ),
                array (
                    'id' => 'home-photo-spotlight-credit',
                    'type' => 'text',
                    'name' => esc_html__( 'Photo Credit', 'tmg' ),
                    'desc' => esc_html__( '(Optional) Add a photo credit for this image.', 'tmg' ),
                ),
            ),
        );
    
        return $meta_boxes;
    }
    

    I need the meta box to show up conditionally on pages with the selected template. This method has worked for me in the past, but I can no longer get it to work properly. Help?

    #17894
    Anh TranAnh Tran
    Keymaster

    Hi,

    In the block editor, the context after_title no longer works. Please use the advanced or normal context. And also change the template to array. This code works:

    'show' => array(
        'template' => ['templates/template-cover.php']
    ),
    'context' => 'advanced',
    #17920
    mzykinmzykin
    Participant

    Great, that works, thanks!

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