Cannot manage to work with a Select field in group

Support MB Group Cannot manage to work with a Select field in group

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #3714
    closemarketingclosemarketing
    Participant

    How it will be the code?

    I use this:

    array(
        				'name'   => esc_html__( 'Depends of', 'pbc' ),
    					'id'     => "{$prefix}depends",
    					'type'   => 'group',
    					'clone'  => true,
    					'sort_clone' => true,
    					'fields' => array(
    		    			// SELECT BOX VARIATIONS
    		    			array(
    		    				'name'        => __( 'Variation', 'pbc' ),
    		    				'id'          => "{$prefix}depvar",
    		    				'type'        => 'select',
    		    				'options'     => $var_options,
    		    				'multiple'    => false,
    		    				'std'         => '',
    		    				'placeholder' => __( 'Select a Variation', 'pbc' ),
    		    			),
    					),
    				), //array
    #3721
    Anh TranAnh Tran
    Keymaster

    Did you set value for $var_options? Here is my test:

    <?php
    add_filter( 'rwmb_meta_boxes', 'your_prefix_register_meta_boxes' );
    function your_prefix_register_meta_boxes( $meta_boxes ) {
        $prefix       = 'mbox_';
        $var_options  = array(
            'a' => 'First option',
            'b' => 'Second option',
        );
        $meta_boxes[] = array(
            'title' => esc_html__( 'Standard Fields', 'your-prefix' ),
    
            'fields' => array(
                array(
                    'name'       => esc_html__( 'Depends of', 'pbc' ),
                    'id'         => "{$prefix}depends",
                    'type'       => 'group',
                    'clone'      => true,
                    'sort_clone' => true,
                    'fields'     => array(
                        // SELECT BOX VARIATIONS
                        array(
                            'name'        => __( 'Variation', 'pbc' ),
                            'id'          => "{$prefix}depvar",
                            'type'        => 'select',
                            'options'     => $var_options,
                            'multiple'    => false,
                            'std'         => '',
                            'placeholder' => __( 'Select a Variation', 'pbc' ),
                        ),
                    ),
                ), //array
            ),
        );
    
        return $meta_boxes;
    }

    And here is the result:

    http://prntscr.com/bvycei

    #3724
    closemarketingclosemarketing
    Participant

    Hello!, yes it loads all entries from a post type:

    //Variations Options
            $var_options = array();
            $variationscpt = get_posts(array(
                'post_type' => 'variation',
                'posts_per_page' => -1,
                'orderby' => 'name',
                'order' => 'ASC'
            ));
            $variationscpt_item = array();
            foreach ($variationscpt as $var_item) {
               $var_options[$var_item->ID] = $var_item->post_title;
            }
    #3725
    closemarketingclosemarketing
    Participant

    Hello, I've found the error. I was using meta-box as composer, and it was not working...

    Now as plugin it works correctly.

Viewing 4 posts - 1 through 4 (of 4 total)
  • The topic ‘Cannot manage to work with a Select field in group’ is closed to new replies.