How to display select_advanced, for each > select > option in frontend

Support MB User Meta How to display select_advanced, for each > select > option in frontend

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #5881
    DanielDaniel
    Participant
    <?php
    
    add_action( 'rwmb_meta_boxes', 'userprofile' );
    function userprofile( $meta_boxes ) {
    
    	$meta_boxes[] = array(
            'id'	=> 'useroptions',
    		'title' => 'User Profile',
    		'type'  => 'user', // Specifically for user
    		'fields' => array(
    
    			array(
    				'name'    => __( 'Country', 'textdomain' ),
    				'id'      => 'country',
    				'type'    => 'select_advanced',
    				'options' => array(
    					'country-us' => 'United States',
    					'country-uk' => 'United Kingdom'
    				),
    			),
    	);
    	return $meta_boxes;
    }
    
    ?>

    I'm trying to display a select>option in the front end that will allow the user to select their option, but with all the documentation I haven't been able to find the for each example.

    #5882
    DanielDaniel
    Participant

    Also looking for a checkbox_list option as well.

    #5884
    Anh TranAnh Tran
    Keymaster

    Hi Daniel,

    There's a documentation on displaying checkbox_list, radio, select value in the frontend.

    However, if you are looking for a way to show options that users can select, I'm afraid you need to write the code yourself. It looks similar to this:

    $options = array(
        'country-us' => 'United States',
        'country-uk' => 'United Kingdom'
    );
    
    echo '<select name="your_name">';
    foreach ( $options as $value => $label ) {
        echo '<option value="' . $value . '">' . $label . '</option>';
    }
    echo '</select>';
    #5887
    DanielDaniel
    Participant

    Thanks Anh,

    Went ahead and wrote my own, all in all this was helpful.

Viewing 4 posts - 1 through 4 (of 4 total)
  • The topic ‘How to display select_advanced, for each > select > option in frontend’ is closed to new replies.