I have done all the child category shows in each parent category. Now I want the current or active category not to be displayed when I am on the category page.
$queried_object = get_queried_object();
$child_terms = get_term_children ( $queried_object->term_id, 'product_cat' );
$main_term = (is_wp_error($child_terms) || empty($child_terms)) ? get_term ( $queried_object->parent, 'product_cat' ) : $queried_object;
$terms_arg = get_terms( 'product_cat', array(
'orderby' => 'name',
'hide_empty' => false,
'parent' => $main_term->term_id,
) );
if( !empty( $terms_arg ) && !is_wp_error( $terms_arg ) ){
foreach( $terms_arg as $display_term ){
printf(
'<div class="cat-list"><h3%s><a href="%s">%s</a></h3></div>',
($display_term->term_id == $queried_object->term_id) ? : '',
esc_url(get_term_link($display_term->term_id)),
$display_term->name,
);
}
}
2
Answers
try this
According to me get_terms() is having the options of exclude under the argument parameter
Try with below code