-
-
Save illucent/8963629 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
<?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