Problem using select field of custom posts from version 2.0.0.4 to 2.0.0.6
-
Thanks so much for your work on this plugin. I started with version 2.0.0.0 and have been upgrading versions along with the development but I noticed an issue when going from version 2.0.0.4 to 2.0.0.6 (I must have skipped 2.0.0.5). I have a select field that is pulling in custom posts. This worked perfectly in version 2.0.0.4, but since upgrading to 2.0.0.6, all the select options appear as Array.
This is my metabox code:
$prefix = '_cmb2_'; $meta_boxes['related_books'] = array( 'id' => 'related_books', 'title' => __( 'Related Books', 'cmb2' ), 'object_types' => array( 'book', ), 'context' => 'normal', 'priority' => 'high', 'show_names' => true, 'fields' => array( array( 'name' => __( 'Heading', 'cmb2' ), 'id' => $prefix . 'related_books_heading', 'default' => 'You may also like', 'type' => 'text', ), array( 'name' => __( 'Select First Related Book', 'cmb' ), 'id' => $prefix . 'related_book__1', 'type' => 'select', 'options' => cmb_get_post_options(), ), array( 'name' => __( 'Select Second Related Book', 'cmb' ), 'id' => $prefix . 'related_book__2', 'type' => 'select', 'options' => cmb_get_post_options(), ), array( 'name' => __( 'Select Third Related Book', 'cmb' ), 'id' => $prefix . 'related_book__3', 'type' => 'select', 'options' => cmb_get_post_options(), ), ), );
and this is the function to pull in the posts:
function cmb_get_post_options( $query_args ) { $args = wp_parse_args( $query_args, array( 'post_type' => 'book', 'numberposts' => -1, 'orderby' => 'title', 'order' => 'ASC', ) ); $posts = get_posts( $args ); $post_options = array('Select Book'); if ( $posts ) { foreach ( $posts as $post ) { $post_options[] = array( 'name' => $post->post_title, 'value' => $post->ID ); } } return $post_options; }
Is there a different format that the function needs to return for this to work now?
At the moment I am working locally (I reverted back to version 2.0.0.4 for the site that is on my server as my client is working with the site for a launch on the 5th) but I can upgrade to the version with the issue and give you access if you need to take a look. I appreciate the help.
- The topic ‘Problem using select field of custom posts from version 2.0.0.4 to 2.0.0.6’ is closed to new replies.