CMB2 loop fileds depending on custom post type count

enter image description here

This is my custom metaboxes:

    add_action( 'cmb2_init', 'cmb2_metaboxes' );
    function cmb2_metaboxes() {

    // Start with an underscore to hide fields from custom fields list
    $prefix = 'mt';

    /**
     * Initiate the metabox
     */
    $cmb = new_cmb2_box( array(
        'id'            => 'Rooms',
        'title'         => __( 'Rooms photo', 'cmb2' ),
        'object_types'  => array( 'accommodation', ), // 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' => $post_title,
        'desc' => 'This is a title description',
        'type' => 'file_list',
        'id'   => $post_slug
    ) );

}

Is it possible to add a loop that will print all post_types = room_type and pass values to the custom metabox fields?

It should looks like:

Read more here: CMB2 loop fileds depending on custom post type count

Leave a Reply

Your email address will not be published. Required fields are marked *