The code works perfectly for listing WooCommerce product tags, but I want to add a query with it.
I would like to list only product tags that contain a specific String.
<?php
$terms = get_terms(array(
'taxonomy' => 'product_tag',
'hide_empty' => false,
));
$count = count($terms);
echo "found ". $count . " Schools";
?>
<div class="product-tags">
<ul>
<?php foreach ( $terms as $term ) { ?>
<li><a href="<?php echo get_term_link( $term->term_id, 'product_tag' ); ?> " rel="tag"><?php echo $term->name; ?></a></li>
<?php } ?>
</ul>
</div>
2
Answers
You can use the ‘search’ or ‘name_like’ fields in the first argument array, per the wordpress documentation here:
https://developer.wordpress.org/reference/classes/wp_term_query/__construct/
For example, say you want to get all terms where the name contains ‘foo’
Use
WP_Term_Query
instead ofget_terms