Custom Fields
Re-Envisioned
Support Meta Box Show Hide (Javascript) Metabox for page template disappears

  • Creator
    Topic
  • #17886
    Resolved mzykin
    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?

Viewing 2 replies - 1 through 2 (of 2 total)
  • Author
    Replies
  • #17894
    Anh 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
    mzykin
    Participant

    Great, that works, thanks!

Viewing 2 replies - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.
grid gear info copy caret-up caret-down trash