Title: multicheck options question
Last modified: August 30, 2016

---

# multicheck options question

 *  Resolved [daco.marseille](https://wordpress.org/support/users/dacomarseille/)
 * (@dacomarseille)
 * [10 years, 8 months ago](https://wordpress.org/support/topic/multicheck-options-question/)
 * Hi,
    first of all thanks so much for your plugin! I love it!
 * I have an issue which I don’t seem to understand,
    I need to build an option 
   array for a multi checkbox, this array is made out of a wp_query
 * Here is the code:
 *     ```
       /*
       * initie metaboxes
       */
   
       add_action( 'cmb2_init', 'cmb2_ratchet_metaboxes' );
       /**
        * Define the metabox and field configurations.
        */
       function cmb2_ratchet_metaboxes() {
   
           // Start with an underscore to hide fields from custom fields list
           $prefix = '_cmb_';
   
       /**
            * Initiate the metabox for Works
            */
           $cmb = new_cmb2_box( array(
               'id'            => 'works_details',
               'title'         => __( 'Work Details', 'cmb2' ),
               'object_types'  => array( 'work', ), // Post type
               'context'       => 'normal',
               'priority'      => 'high',
               'show_names'    => true, // Show field names on the left
               // 'cmb_styles' => false, // false to disable the CMB stylesheet
               // 'closed'     => true, // Keep the metabox closed by default
           ) );
   
       	$cmb->add_field( array(
               'name'       => __( 'Work main image', 'cmb2' ),
               'desc'       => __( 'Work main image, dimensions: 1920px x 380px', 'cmb2' ),
               'id'         => $prefix . 'work_main_img',
               'type' => 'file',
           ) );
   
       	/*custom query to build multicheckbox options*/
       	$clientsArray = array();
       	$subs = new WP_Query( array(  'post_type' => 'client', 'orderby' => 'date','posts_per_page'=>'-1' ));
       	if( $subs->have_posts() ) : while( $subs->have_posts() ) : $subs->the_post();
       	$postid = $post->ID;
       	$title = get_the_title( $postid );
       	$clientsArray[$postid] = $title;
       	endwhile;
       	endif; wp_reset_postdata();
   
       	$cmb->add_field( array(
       		'name'    => __( 'Clients', 'cmb2' ),
       		'desc'    => __( 'check clients (optional)', 'cmb2' ),
       		'id'      => $prefix . 'multicheckbox_clients',
       		'type'    => 'multicheck',
       		//'multiple' => true, // Store values in individual rows
       		'options' => $clientsArray,
       		'inline'  => true, // Toggles display to inline
       	) );
       }
       ```
   
 * The problem is at the very end,
    $clientsArray is not recognised, when I print_r
   it it gives: `Array ( [27] => Argos [26] => Google )`
 * When I switch and enter manually the options:
 * `'options' => Array ( 27 => 'Argos', 26 => 'Google' ),`
 * It works like a charm,
 * I don’t know what I’m missing,
    but if you could help that would be great!
 * Thank you!
 * [https://wordpress.org/plugins/cmb2/](https://wordpress.org/plugins/cmb2/)

Viewing 3 replies - 1 through 3 (of 3 total)

 *  Plugin Author [Justin Sternberg](https://wordpress.org/support/users/jtsternberg/)
 * (@jtsternberg)
 * [10 years, 8 months ago](https://wordpress.org/support/topic/multicheck-options-question/#post-6574292)
 * There is an example in the wiki demonstrating exactly what you’re looking for:
   [https://github.com/WebDevStudios/CMB2/wiki/Adding-your-own-field-types#example-2-posts-or-other-post_type-dropdown-store-post_id](https://github.com/WebDevStudios/CMB2/wiki/Adding-your-own-field-types#example-2-posts-or-other-post_type-dropdown-store-post_id)
 *  Thread Starter [daco.marseille](https://wordpress.org/support/users/dacomarseille/)
 * (@dacomarseille)
 * [10 years, 8 months ago](https://wordpress.org/support/topic/multicheck-options-question/#post-6574315)
 * Yeah!
    Thanks so much for this! Just to let you know, there is a missing `;` 
   on the documentation at the end of the return of the cmb2_get_your_post_type_post_options
   function
 * Thanks again for your work and your help!
 *  Plugin Author [Justin Sternberg](https://wordpress.org/support/users/jtsternberg/)
 * (@jtsternberg)
 * [10 years, 8 months ago](https://wordpress.org/support/topic/multicheck-options-question/#post-6574321)
 * Fixed the typo, thanks!

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘multicheck options question’ is closed to new replies.

 * ![](https://ps.w.org/cmb2/assets/icon.svg?rev=2866672)
 * [CMB2](https://wordpress.org/plugins/cmb2/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/cmb2/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/cmb2/)
 * [Active Topics](https://wordpress.org/support/plugin/cmb2/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/cmb2/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/cmb2/reviews/)

 * 3 replies
 * 2 participants
 * Last reply from: [Justin Sternberg](https://wordpress.org/support/users/jtsternberg/)
 * Last activity: [10 years, 8 months ago](https://wordpress.org/support/topic/multicheck-options-question/#post-6574321)
 * Status: resolved