Last active
August 29, 2015 14:17
-
-
Save JuanRangel/0934cbc3dec20e3b1ce8 to your computer and use it in GitHub Desktop.
Get all terms from a taxonomy and use a select 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
function get_tax_options( $taxonomy, $field ) { | |
$terms = get_terms( $taxonomy ); | |
$current = ( isset($_POST[$field]) ) ? $_POST[$field] : ''; | |
$options = array(); | |
$options[] = '<option value="">-- ' . ucwords( $taxonomy ) .' --</option>'; | |
if ( ! empty( $terms ) && ! is_wp_error( $terms ) ){ | |
foreach ( $terms as $term ) { | |
$options[] = sprintf( '<option value="%s" %s>%s</option>', $term->slug ,selected( $current, $term->slug ), $term->name ); | |
} | |
} | |
return implode( ' ', $options );; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment