Checkbox List and Select Advanced (multiple true) returning a string

Support General Checkbox List and Select Advanced (multiple true) returning a string

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #46511
    MondenMonden
    Participant

    I have both checkbox_list and select_advanced (which has multiple => true) returning a string instead of array even though multiple choices are selected. Why?

    
    // ----- field
    [
    	'name'				=> esc_html__( 'My Checkbox', 'textdomain' ),
    	'label_description'	=> esc_html__( 'My Checkbox', 'textdomain' ),
    	'id'				=> 'checkbox_list_field_id',
    	'type'				=> 'checkbox_list',
    	'inline'			=> false,
    	'select_all_none'	=> false,
    	'options'			=> [
    		'option_1'	=> esc_html__( 'Option 1', 'textdomain' ),
    		'banana'	=> esc_html__( 'Banana', 'textdomain' ),
    		'potato'	=> esc_html__( 'Potato', 'textdomain' ),
    	],
    ],
    // ----- then in code
    $args = [
    	'post_type' => 'my_custom_post',
    	'author__in' => $array_of_user_ids,
    	'posts_per_page' => -1
    ];
    
    $query = new WP_Query( $args );
    
    if ( $query->have_posts() ) {
    	while ( $query->have_posts() ) {
    		$query->the_post();
    		$checkbox_list = rwmb_meta( 'checkbox_list_field_id' );
    		var_dump($checkbox_list);
    		if ( !is_array( $checkbox_list ) ) {
    			echo '<h3 style="z-index:100000000000; background: red; padding: 60px; display: block;">NOT ARRAY</h3>';
    			die();
    		} else {
    			echo '<h3 style="z-index:100000000000; background: red; padding: 60px; display: block;">YES ARRAY</h3>';
    			die();
    		}	
    	}
    
    	wp_reset_postdata();
    }
    #46513
    MondenMonden
    Participant

    rwmb_meta fails/returns a string (why), but this works: $checkbox_list = get_post_meta( get_the_ID(), 'checkbox_list_field_id' );

    #46516
    PeterPeter
    Moderator

    Hello,

    You can try to pass the post ID to the helper function, like get_post_meta(), and check the issue again. For example:

    $checkbox_list = rwmb_meta( 'checkbox_list_field_id', '', get_the_ID() );

    Following the documentation https://docs.metabox.io/functions/rwmb-meta/

Viewing 3 posts - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.