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.

1 Answer 1


Finally 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;   

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.