Is it possible to hide taxonomies without categories. I'm using get_object_taxonomies to show all my taxonomies inside my custom post type.
<?php
$blog_taxonomies = get_object_taxonomies( 'blog', 'textdomain',
(array(
'hide_empty' => true,
))
);
foreach ($blog_taxonomies as $blog_taxonomy) :
?>
<ul >
<li > <?= $blog_taxonomy->labels->name; ?> </li>
<?php endforeach; ?>
CodePudding user response:
You can use the code below. The parameters you submitted to get_object_taxonomies are incorrect.
$taxonomy_objects = get_object_taxonomies('blog', 'objects');
foreach ($taxonomy_objects as $taxonomy) {
$taxonomy_terms = get_terms(['taxonomy' => $taxonomy->name, 'hide_empty' => true]);
if (!empty($taxonomy_terms)) {
return;
}
// Your operation
}
See get_object_taxonomies documentation.
CodePudding user response:
use get_object_taxonomies
function like this
$taxonomy_objects = get_object_taxonomies( array( 'post', 'product' ), 'objects' );
foreach ( $taxonomy_objects as $taxonomy ) {
$taxonomy_terms = get_terms( array( 'taxonomy' => $taxonomy->name, 'hide_empty' => true ) );
//var_dump($taxonomy_terms);
}