Custom Metaboxes and Fields (CMB) will create metaboxes and forms with custom fields that will blow your mind. This is version 2.0 and has been completely rewritten.
Hi everybody. I've already implements this code:
function cmb2_post_search_ajax_metaboxes_example() {
$example_meta = new_cmb2_box( array(
'id' => 'cmb2_post_search_ajax_field',
'title' => __( 'Related Posts', 'cmb2' ),
'object_types' => array( 'movie' ), // Post type
'context' => 'normal',
'priority' => 'high',
'show_names' => true, // Show field names on the left
) );
$example_meta->add_field( array(
'name' => ( 'Example Multiple', 'cmb2' ),
'id' => 'cmb2_post_search_ajax_demo_multiple',
'type' => 'post_search_ajax',
'desc' => ( '(Start typing post title)', 'cmb2' ),
// Optional :
'limit' => 10, // Limit selection to X items only (default 1)
'sortable' => true, // Allow selected items to be sortable (default false)
'query_args' => array(
'post_type' => array( 'movie' ),
'post_status' => array( 'publish' ),
'posts_per_page' => -1
)
) );
$example_meta->add_field( array(
'name' => ( 'Example Single', 'cmb2' ),
'id' => 'cmb2_post_search_ajax_demo_single',
'type' => 'post_search_ajax',
'desc' => ( '(Start typing post title)', 'cmb2' ),
// Optional :
'limit' => 1, // Limit selection to X items only (default 1)
'sortable' => false, // Allow selected items to be sortable (default false)
'query_args' => array(
'post_type' => array( 'movie' ),
'post_status' => array( 'publish' ),
'posts_per_page' => -1
)
) );
}
add_action( 'cmb2_init', 'cmb2_post_search_ajax_metaboxes_example' );