Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // paste below code in your functions.php
- function cmb2_get_post_options( $query_args ) {
- $args = wp_parse_args( $query_args, array(
- 'post_type' => 'post',
- 'numberposts' => 10,
- ) );
- $posts = get_posts( $args );
- $post_options = array();
- if ( $posts ) {
- foreach ( $posts as $post ) {
- $post_options[ $post->ID ] = $post->post_title;
- }
- }
- return $post_options;
- }
- function cmb2_get_your_post_type_post_options() {
- return cmb2_get_post_options( array( 'post_type' => 'your_post_type', 'numberposts' => 5 ) );
- }
- // and this given below post paste in your meta data file
- $cmb_demo->add_field( array(
- 'name' => __( 'Select your_post_type Posts', 'cmb2' ),
- 'desc' => __( 'field description (optional)', 'cmb2' ),
- 'id' => $prefix . 'post_multicheckbox',
- 'type' => 'multicheck',
- 'options_cb' => 'cmb2_get_your_post_type_post_options',
- ) );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement