终于想出了解决办法。如果有人觉得有用就回答。哪里$_GET[\'s_qr\']
具有来自另一个页面的用户的搜索查询。
$i = 0;
$parent_name = \'\';
$taxonomyName = "product-cat";
$search_r = array();
$parent_terms = get_terms( $taxonomyName, array( \'parent\' => 0, \'orderby\' => \'slug\', \'hide_empty\' => false ) );
foreach ( $parent_terms as $pterm ) {
$parent_name_1 = $pterm->name;
$terms = get_terms( $taxonomyName, array( \'parent\' => $pterm->term_id, \'orderby\' => \'slug\', \'hide_empty\' => false ) );
foreach ( $terms as $term ) {
//Find if the the category name has the search query
if (stripos($term->name, $_GET[\'s_qr\']) !== false) {
$search_r[\'item\'][$i] = $term->name. " in ".$parent_name_1;
$i++;
}
}
}
print_r($search_r);