Advertisement
Guest User

Untitled

a guest
Mar 23rd, 2017
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.92 KB | None | 0 0
  1. // paste below code in your functions.php
  2.  
  3. function cmb2_get_post_options( $query_args ) {
  4.  
  5. $args = wp_parse_args( $query_args, array(
  6. 'post_type' => 'post',
  7. 'numberposts' => 10,
  8. ) );
  9.  
  10. $posts = get_posts( $args );
  11.  
  12. $post_options = array();
  13. if ( $posts ) {
  14. foreach ( $posts as $post ) {
  15. $post_options[ $post->ID ] = $post->post_title;
  16. }
  17. }
  18.  
  19. return $post_options;
  20. }
  21.  
  22.  
  23. function cmb2_get_your_post_type_post_options() {
  24. return cmb2_get_post_options( array( 'post_type' => 'your_post_type', 'numberposts' => 5 ) );
  25. }
  26.  
  27.  
  28.  
  29.  
  30.  
  31. // and this given below post paste in your meta data file
  32.  
  33. $cmb_demo->add_field( array(
  34. 'name' => __( 'Select your_post_type Posts', 'cmb2' ),
  35. 'desc' => __( 'field description (optional)', 'cmb2' ),
  36. 'id' => $prefix . 'post_multicheckbox',
  37. 'type' => 'multicheck',
  38. 'options_cb' => 'cmb2_get_your_post_type_post_options',
  39. ) );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement