最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

custom post types - How to search through all child taxonomies using WP_Query?

programmeradmin0浏览0评论

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 1
Add a comment  | 

1 Answer 1

Reset to default 0

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;   
                $i++;
            }
        }
    }
    print_r($search_r);
发布评论

评论列表(0)

  1. 暂无评论