<?php
// Example: Displaying all terms for a custom taxonomy
// Replace 'your_custom_taxonomy' with your custom taxonomy slug
$taxonomy_slug = 'your_custom_taxonomy';
// Get all terms for the custom taxonomy
$terms = get_terms(array(
'taxonomy' => $taxonomy_slug,
'hide_empty' => false, // Set to true to hide terms with no associated posts
));
// Check if there are terms available
if (!is_wp_error($terms) && !empty($terms)) {
echo '<ul>';
foreach ($terms as $term) {
// Display term name and link to its archive page
echo '<li>';
echo '<a href="' . esc_url(get_term_link($term)) . '">' . esc_html($term->name) . '</a>';
echo ' (' . esc_html($term->count) . ' posts)'; // Display post count if needed
echo '</li>';
}
echo '</ul>';
} else {
echo '<p>No terms found for this taxonomy.</p>';
}
?>