Created
August 16, 2014 16:41
-
-
Save mustardBees/40e64d44060d8718c2d0 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 | |
/** | |
* Gets a number of terms and displays them as options | |
* | |
* Modified from CMB example code to save the term ID instead of slug. | |
* | |
* @link http://link.from.pw/1sLyqqv | |
* @param string $taxonomy Taxonomy terms to retrieve. Default is category | |
* @param string|array $args Optional. Change the defaults retrieving terms | |
* @return array An array of options that matches the CMB options array | |
*/ | |
function pw_cmb_get_term_options( $taxonomy = 'category', $args = array() ) { | |
$args['taxonomy'] = $taxonomy; | |
$args = wp_parse_args( $args, array( 'taxonomy' => 'category' ) ); | |
$taxonomy = $args['taxonomy']; | |
$terms = (array) get_terms( $taxonomy, $args ); | |
// Initate an empty array | |
$term_options = array(); | |
if ( ! empty( $terms ) ) { | |
foreach ( $terms as $term ) { | |
$term_options[ $term->term_id ] = $term->name; | |
} | |
} | |
return $term_options; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment