Skip to content

Instantly share code, notes, and snippets.

@schoenwaldnils
Last active July 26, 2016 15:35
Show Gist options
  • Save schoenwaldnils/00a544e35a6917cec7cc9602c2397c4c to your computer and use it in GitHub Desktop.
Save schoenwaldnils/00a544e35a6917cec7cc9602c2397c4c to your computer and use it in GitHub Desktop.
Create array for custom taxonomies
function array_post_taxonomies($the_id) {
$content = [];
$args = array( 'public' => true, '_builtin' => false );
$output = 'objects';
$operator = 'and';
$taxonomies = get_taxonomies( $args, $output, $operator );
if( $taxonomies ) {
foreach( $taxonomies as $taxonomy ) {
$terms = wp_get_post_terms($the_id, $taxonomy->name);
$term = $terms[0]->name;
if (!empty($terms)) {
$content[] = array(
'title' => $taxonomy->labels->singular_name,
'term' => $term
);
}
}
}
return $content;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment