Woocommerce tag list having specific string Woocommerce tag list having specific string wordpress wordpress

Woocommerce tag list having specific string


Use WP_Term_Query instead of get_terms

$keyword = 'tag';// Args$args = array(    'taxonomy'    => 'product_tag',    'hide_empty'  => false,    'name__like'  => $keyword,);// Term Query$query = new WP_Term_Query($args);// Get terms$get_terms = $query->get_terms();// Count$count = count( $get_terms );echo "found ". $count . " Schools";// Loopforeach ( $get_terms as $terms ) {    echo $terms->name;}


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'

<?php $terms = get_terms(array(    'taxonomy' => 'product_tag',     'hide_empty' => false,    'name__like' => '%foo%'));