0

I want to add an if statment, this code echos the child categories for the current category, but I only want it to show IF the child categories are true.

Any help would be great - thank you.

<?php (
$terms = get_terms([
    'taxonomy' => get_queried_object()->taxonomy,
    'parent'   => get_queried_object_id(),
]));
echo '<div style="height: 200px; text-transform: uppercase; border:1px solid #666666; padding:10px; overflow-y: scroll;">
<div class="breaker-small">Refine Search</div>';
foreach ( $terms as $term) {
    echo '<p class="filters"><a href="' . get_term_link( $term ) . '">' . $term->name . '</a></p>';  
}
echo '</div>
<br />';
?>

1 Answer 1

0

If you asking about $terms has child then only go for it. With this you can try below code as solution:

<?php (
    $terms = get_terms([
        'taxonomy' => get_queried_object()->taxonomy,
        'parent'   => get_queried_object_id(),
        'hide_empty' => false
    ]));
    // get_terms will return false if taxonomy does not exist or term wasn't found.
    // term has children
    if($terms){
        echo '<div style="height: 200px; text-transform: uppercase; border:1px solid #666666; padding:10px; overflow-y: scroll;">
                        <div class="breaker-small">Refine Search</div>';
                         foreach ( $terms as $term) {
                            echo '<p class="filters"><a href="' . get_term_link( $term ) . '">' . $term->name . '</a></p>';  
                         }
        echo '</div><br />';
    }
?>

I hope my this code work for you!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.