Custom Fields
Re-Envisioned
Support Meta Box Group Cannot manage to work with a Select field in group

  • Creator
    Topic
  • #3714
    closemarketing
    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
Viewing 3 replies - 1 through 3 (of 3 total)
  • Author
    Replies
  • #3721
    Anh 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
    closemarketing
    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
    closemarketing
    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 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Cannot manage to work with a Select field in group’ is closed to new replies.