I want to display a list of categories excluding the category of the current single post that the user is navigating on. The list is displayed on the single.php
template.
I'm using this code to display all categories and is working well but I can't find a way to exclude the current post category:
<ul class="submenu-category">
<?php
// your taxonomy name
$tax = 'category';
// get the terms of taxonomy
$terms = get_terms( $tax, $args = array(
'hide_empty' => false, // do not hide empty terms
));
// loop through all terms
foreach( $terms as $term ) {
// Get the term link
$term_link = get_term_link( $term );
if( $term->count > 0 )
// display link to term archive
// echo '<a href="' . esc_url( $term_link ) . '">' . $term->name .'</a>';
echo '<li><a data-filter=".'. $term->slug .'" href="javascript:void(0)" >' . $term->name .'</a></li>';
elseif( $term->count !== 0 )
// display name
echo '' . $term->name .'';
} ?>
</ul>
Any idea on how to achieve it?