Last active
July 9, 2024 13:52
-
-
Save enricodeleo/7157359 to your computer and use it in GitHub Desktop.
Get and list all the taxonomies attached to a custom post type in Wordpress
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 | |
$taxonomy_objects = get_object_taxonomies( 'cpt', 'objects' ); // <--- change cpt with the custom post type | |
$out = array(); | |
foreach ( $taxonomy_objects as $taxonomy_slug => $taxonomy ){ | |
$terms = get_terms( $taxonomy_slug, 'hide_empty=0' ); | |
if ( !empty( $terms ) ) { | |
$out[] = "<strong>" . $taxonomy->label . "</strong>\n<ul>"; | |
foreach ( $terms as $term ) { | |
$out[] = | |
" <li>" | |
. $term->name | |
. " </li>\n"; | |
} | |
$out[] = "</ul>\n"; | |
} | |
} | |
echo implode('', $out ); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment