Search code examples
phpwordpresstaxonomy

Hi How to get child terms from a specific term and exclude some specific terms


I am struggling to add 'exclude' to exclude some terms for the below code. I cannot find the correct way to write such an array. Can anyone help me? Thanks

<?php
$terms = get_terms( 'product_cat', 'parent=175' );
$count = count($terms);
if ( $count > 0 ){
    echo '<ul>';
    foreach ( $terms as $term ) {
        echo '<li><a href="'. get_term_link( $term ) .'">'. $term->name . '</a></li>';
    }
    echo '</ul>';
}
?>

Solution

  • your usage of get_terms is incorrect. it takes an array of arguments like so:

    
    $terms = get_terms( array( 
     'taxonomy' => 'product_cat',
     'parent'   =>  $parent_id,
     'exclude'  =>  array( $ids, $to, $exclude )
     ) );