Skip to content

Instantly share code, notes, and snippets.

@illucent
Forked from mustardBees/metaboxes.php
Created February 12, 2014 20:13
Show Gist options
  • Save illucent/8963629 to your computer and use it in GitHub Desktop.
Save illucent/8963629 to your computer and use it in GitHub Desktop.
<?php
/**
* Get a list of downloads
*
* Return an array of downloads suitable for CMB's select field.
*
* Example CMB select field usage:
*
* array(
* 'name' => 'Download',
* 'id' => $prefix . 'download',
* 'type' => 'select',
* 'options' => pw_get_downloads()
* ),
*
* @author Phil Wylie
* @link http://goo.gl/c0bPb
* @return array $downloads_array Array containing titles and post IDs
*/
function pw_get_downloads() {
$args = array(
'posts_per_page' => -1,
'post_type' => 'download',
'orderby' => 'title',
'order' => 'ASC'
);
$downloads = new WP_Query( $args );
$downloads_array = array();
if ( $downloads->have_posts() ) {
while ( $downloads->have_posts() ) {
$downloads->the_post();
$downloads_array[] = array(
'name' => get_the_title(),
'value' => get_the_ID()
);
}
}
wp_reset_postdata();
return $downloads_array;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment