rwmb_meta object_type settings in rwmb_meta_boxes

Support MB Settings Page rwmb_meta object_type settings in rwmb_meta_boxes

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #39348
    marcodedomarcodedo
    Participant

    Hi I have a meta-box that shows fields in pages and posts. Also I have a settings page with a checkbox field that when disabled should hide the meta-box in the pages/posts and show another one.

    I tried to insert this, but the variable $enable is not loaded:

    add_filter( 'rwmb_meta_boxes', 'sidebar_post' );
    
    function sidebar_post( $meta_boxes ) {
    
        $enable = rwmb_meta( 'enable', array( 'object_type' => 'setting' ), 'my_settings' );
    
        if ( $enable ) {
            
            $meta_boxes[] = [
                'title'      => __( 'Set View', 'my-name' ),
                'id'         => 'set-view',
                'context'    => 'side',
                'fields'    => [
                    [
                        'type' => 'custom_html',
                        'std'  => '<div class="alert alert-warning">My first custom message here.</div>',
                    ],
                ],
    
            ];
    
        } else {
    
            $meta_boxes[] = [
                'title'      => __( 'Set View', 'my-name' ),
                'id'         => 'set-view',
                'context'    => 'side',
                'fields'    => [
                    [
                        'type' => 'custom_html',
                        'std'  => '<div class="alert alert-warning">My second custom message here.</div>',
                    ],
                ],
    
            ];
    
        }
    
        return $meta_boxes;
    }
    #39357
    PeterPeter
    Moderator

    Hello there,

    I see you've created another topic with the same question https://support.metabox.io/topic/code-not-working-with-updated-version/

    Please use the WordPress function get_option() to get the field value when registering the meta box and custom fields.

    add_filter( 'rwmb_meta_boxes', 'sidebar_post' );
    function sidebar_post( $meta_boxes ) {
        $enable = get_option( 'my_settings' )['enable'];
        if ( $enable ) {
    ...
    
Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.