I made a few custom taxonomies and I need to show ALL the terms from it, what I achieved so far is showing the taxonomies that are selected/chosen in a custom post type but I need all of them to show, wether it’s selected or not.
So that later I can make a filter that filters according to which terms a custom post type value contains.
<?php
$args=array(
'public' => true,
'_builtin' => false
);
$output = 'names'; // or objects
$operator = 'and';
$taxonomies=get_taxonomies($args,$output,$operator);
if ($taxonomies) {
foreach ($taxonomies as $taxonomy ) {
$terms = get_terms($taxonomy);
foreach ( $terms as $term) {
?>
<li><br><a href="#"><input type="checkbox" name="profile[]" value=""><?php echo $term->name; ?> <br/></a></li>
<?php
}
}
}
?>
What I have so far.
Thanks in advance!
You need to pass an additional argument to
get_terms()
. The default is to hide “empty” terms– terms which are assigned to no posts.EDIT:
Incase you want to display the name or the slug of the enlisted custom taxonomies being held by the $terms variable you can use this piece of code bellow:
Where
$term->slug
outputs the slug of the taxonomy item that’s enlisted and$term->name
outputs the name of the according taxonomy item.Since 4.5.0, taxonomies should be passed via the âtaxonomyâ argument in the $args array so:
where terms that have no posts are hidden by default.
This code is fetches all category and subcategory custom taxonomies using
get_terms()
: