I need to create a page in which I can search through child taxonomies(custom child-category) based on GET request (For example $_GET['search_cat']
) using WP_QUERY
. I just want to list all of the sub-categories of any category based on the query from a user from a different page.
Now, how can I list all of the subcategories searching through all of the subcategories of any category (which are actually custom taxonomy)?
Thanks in Advance.
I need to create a page in which I can search through child taxonomies(custom child-category) based on GET request (For example $_GET['search_cat']
) using WP_QUERY
. I just want to list all of the sub-categories of any category based on the query from a user from a different page.
Now, how can I list all of the subcategories searching through all of the subcategories of any category (which are actually custom taxonomy)?
Thanks in Advance.
Share Improve this question asked May 2, 2020 at 18:05 AppoloniasAppolonias 11 Answer
Reset to default 0Finally figured out the solution. Answering it if anyone finds it useful. Where $_GET['s_qr']
has a search query from a user from another page.
$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);