This website uses cookies to personalize your experience. By using this website you agree to our cookie policy.

Taxonomy Filter could not get all results

Home Forums Product Support Forums Ajax Search Pro for WordPress Support Taxonomy Filter could not get all results

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #21138
    gianghl1983gianghl1983
    Participant

    Hi,

    I used Taxonomy Filter for my search. On this page: https://raovat24s.vn/dien-tu-dien-may , there are more than 10 posts. However, by select ĐIỆN TỬ – ĐIỆN MÁY from select box get only 1 result.

    ĐIỆN TỬ – ĐIỆN MÁY 1 a parent category = 1 post assigned to it, but there are around 9 other post assigned to its children category.

    It is a very long list if I select all children category for drop down filter (around 100). So is there any way by selecting parent category the result cover all its children’s posts?

    Thanks!

    #21149
    Ernest MarcinkoErnest Marcinko
    Keymaster

    Hi!

    Well, there is no option for that, because if the parent categoriy is not assigned to the child, then it is not considered as part of it. There might be however a solution, by using a custom code.

    Try adding this custom code to the functions.php in your theme/child theme directory. Before editing, please make sure to have a full site back-up just in case!

    /**
     * Scenario: Drop-down mode taxonomy filter, posts in child categories, not included in parent categories
     * This snippet will include the child categories, when the parent is selected, and changes the logic accordingly
     * 
     * @param $args
     * @return mixed
     */
    add_filter('asp_query_args', 'asp_tax_filter_include_child_terms', 10, 1);
    function asp_tax_filter_include_child_terms( $args ) {
    	$taxonomy = 'category'; // Change this to the taxonomy name
    
    	// ---- Taxonomy term replacement ----
    	foreach ($args['post_tax_filter'] as $k=>&$item) {
    		if ( $item['taxonomy'] != $taxonomy ) continue;
    		$children = array();
    		if ( count($item['include']) > 0 ) {
    			foreach($item['include'] as $tid)
    				$children = array_merge($children, get_term_children( $tid, $taxonomy ));
    		}
    		$item['include'] = array_merge($item['include'], $children);
    		$item['logic'] = 'or';
    	}
    	return $args;
    }
    #21162
    gianghl1983gianghl1983
    Participant

    Thank you!

    It works perfectly.

    Have a nice day! 🙂

Viewing 3 posts - 1 through 3 (of 3 total)
  • The topic ‘Taxonomy Filter could not get all results’ is closed to new replies.