Home › Forums › Product Support Forums › Ajax Search Pro for WordPress Support › Including Taxonomy Name next to Terms in Results
This topic contains 2 replies, has 2 voices, and was last updated by atoohill 6 years, 11 months ago.
- AuthorPosts
- October 5, 2016 at 5:14 pm #10375
When taxonomy terms are returned as results is there a way to include the taxonomy name next to the taxonomy term? Example, I have a taxonomy name “Speaker”. When the results return it would be nice for it to look like this: “Speaker – Speaker Name”, instead of just “Speaker”. Is there a function or something in the settings I’m not seeing that would make this possible? It’d be incredibly useful for us. Thank-you.
October 6, 2016 at 7:47 am #10383Hi!
Yes, actually it is possible. I’ve put together a small code snippet for you, put it in the functions.php file in your active theme directory:
add_filter( 'asp_results', 'asp_taxonomy_names_in_terms', 1, 1 ); function asp_taxonomy_names_in_terms( $results ) { foreach ($results as $k=>$v) { if ( $v->content_type == 'term' ) { $t = get_taxonomy( $v->taxonomy ); if ( !is_wp_error($t) ) $results[$k]->title = $t->label . ' - ' . $results[$k]->title; } } return $results; }
This should do the trick 🙂
Best,
Ernest Marcinko
If you like my products, don't forget to rate them on codecanyon :)
October 7, 2016 at 5:13 pm #10401Hey, that did the trick, thanks so much!
- AuthorPosts
You must be logged in to reply to this topic.