Created
October 22, 2014 19:27
-
-
Save bearded-avenger/ff479f01bc1bbf24fbf1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Gets a number of posts and displays them as options | |
* @param array $query_args Optional. Overrides defaults. | |
* @return array An array of options that matches the CMB options array | |
*/ | |
function cgc_get_posts_for_cmb( $query_args ) { | |
$args = wp_parse_args( $query_args, array( | |
'post_type' => array('post'), | |
'numberposts' => -1, | |
) ); | |
$posts = get_posts( $args ); | |
$post_options = array(); | |
if ( $posts ) { | |
foreach ( $posts as $post ) { | |
$type = $post->post_type; | |
$post_options[] = array( | |
'name' => strtoupper($type).': '.$post->post_title, | |
'value' => $post->ID | |
); | |
} | |
} | |
return $post_options; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class cgcFlowsMeta{ | |
public function __construct(){ | |
add_filter( 'cmb2_meta_boxes', array($this,'flows_meta') ); | |
} | |
public function flows_meta( array $meta_boxes ) { | |
$meta_boxes[] = array( | |
'id' => 'cgc-flow-setup', | |
'title' => __('Flow Setup', 'cgc-flows'), | |
'object_types' => array('cgc_flows'), | |
'fields' => array( | |
array( | |
'id' => 'cgc_flow_tracks', | |
'name' => __('Flow Tracks', 'cgc-flows'), | |
'type' => 'group', | |
'options' => array( | |
'group_title' => __( 'Track {#}', 'cgc-flows' ), // {#} gets replaced by row number | |
'add_button' => __( 'Add Another Track', 'cgc-flows' ), | |
'remove_button' => __( 'Remove Track', 'cgc-flows' ), | |
'sortable' => true | |
), | |
'repeatable' => true, | |
'desc' => __('', 'cgc-flows'), | |
'fields' => array( | |
array( | |
'id' => 'track_connections', | |
'name' => __('Post to Connect', 'cgc-flows'), | |
'type' => 'select', | |
'options' => cgc_get_posts_for_cmb(array('post_type' => array( 'cgc_quiz','cgc_courses') )), | |
'repeatable' => true | |
) | |
) | |
) | |
) | |
); | |
return $meta_boxes; | |
} | |
} | |
new cgcFlowsMeta; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment