Home › Forums › Product Support Forums › Ajax Search Pro for WordPress Support › Filter against custom taxonomy › Reply To: Filter against custom taxonomy
February 12, 2014 at 2:13 pm
#969
Good news. If you want to show the taxonomy terms in the result I have a working solution. You will need to open up the plugins/ajax-search-pro/search.php file and go to line 141, where you should see this:
$params = array('data'=>$search['data'], 'options'=>$search['options']);
After this line, instert the following code:
/* Extra for searching custom taxonomies */ function _getAllTaxonomies() { $args = array( 'public' => true, '_builtin' => false ); $output = 'names'; // or objects $operator = 'and'; // 'and' or 'or' $taxonomies = get_taxonomies( $args, $output, $operator ); return $taxonomies; } function _getLikeTerms($name) { $taxonomies = _getAllTaxonomies(); $terms = array(); foreach ($taxonomies as $taxonomy) { $terms[$taxonomy] = get_terms($taxonomy, array( 'orderby' => 'name', 'name__like' => $name )); } return $terms; } $_like_terms = _getLikeTerms($s); $_termres = array(); foreach ($_like_terms as $taxonomy=>$terms) { foreach ($terms as $term) { //var_dump($term); $_termo = new stdClass(); $_termo->id = $term->term_id; $_termo->content = ""; $_termo->title = $term->name; $_termo->date = ""; $_termo->author = ""; $_termo->image = ""; $_termo->link = get_term_link( $term, $term->taxonomy ); $_termres[] = $_termo; } } $allpageposts = array_merge($allpageposts, $_termres); /* END Extra for searching custom taxonomies */
And that’s it. Not sure how efficient this is, but this should work 🙂
Best,Ernest Marcinko
If you like my products, don't forget to rate them on codecanyon :)



