Hello,
I have a 'Custom Post Type' with 8 taxonomies and I'm pretending display a list with only 6 taxonomies and the no empties terms of each one and hide 2 taxonomies.
My current code displays all taxonomies with all terms hiding the empties one but I can not get how to hide the two taxonomies I want.
This is my code:
<? php
$args = array(
'public' => true,
'_builtin' => false
);
// $output = 'names'; // or objects
// $operator = 'and'; // 'and' or 'or'
// $taxonomies = get_taxonomies( $args, $output, $operator );
$object = 'my-cpt-name';
$output = 'names';
$taxonomies = get_object_taxonomies( $object, $output );
if ( $taxonomies ) {
foreach ( $taxonomies as $taxonomy ) {
echo '<h3>' . $taxonomy . '</h3>';
$args = array( 'hide_empty=0' );
$terms = get_terms( $taxonomy, $args );
if ( ! empty( $terms ) && ! is_wp_error( $terms ) ) {
$count = count( $terms );
$i = 0;
$term_list = '<ul class="term-list">';
foreach ( $terms as $term ) {
$i++;
$term_list .= '<li><a href="' . esc_url( get_term_link( $term ) ) . '" >' . $term->name . '</a></li>';
if ( $count != $i ) {
}
else {
$term_list .= '</ul>';
}
}
echo $term_list;
}
}
}
?>
I have set up the 'public' taxonomy $arg as 'false' but doesn't work.
$args = array(
'labels' => $labels,
'hierarchical' => true,
'public' => false,
'show_ui' => true,
'show_admin_column' => true,
'show_in_nav_menus' => true,
'show_tagcloud' => true,
);
And also, how could I display the taxonomy name instead of the taxonomy slug on echo '<h3>' . $taxonomy . '</h3>';