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

Reply To: 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 Reply To: Taxonomy Filter could not get all results

#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;
}