• Resolved Tanveer

    (@tanver)


    Hi there,
    I am trying to create a Custom Query by making use of Elementor’s built in Action Hook, “Custom Query Filter” to get all the Child’s of Parent ‘Products’ Category. It always fails to fetch the desired Sub-Categories. The Code I am using is as below:

    function products_sub_categories( $query ) {
    	// Get the ID of the "Products" category
        $parent_category_id = get_term_by('slug', 'products', 'product_cat')->term_id;
    
    	$args = array(
    		'taxonomy'           => 'product_cat',
    		'parent'             => $parent_cat_id,
    		'orderby'            => 'name',
    		'show_count'         => 0,
    		'pad_counts'         => 0,
    		'hierarchical'       => 1,
    		'title_li'           => '',
    		'hide_empty'         => 0
    	);
    
    	$sub_cats = get_categories( $args );	
    	
    	$query->set('category', $sub_cat);
    }
    add_action( 'elementor/query/get_sub_categories', 'products_sub_categories' );

    I have tested it and found that somehow I am unable to set the Query Parameter correctly to effect the desired results.

    I will appreciate if someone can quickly bail me out of this mess.

Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
  • The topic ‘Using “Custom Query Filter” for Child Categories’ is closed to new replies.