Home › Forums › Product Support Forums › Ajax Search Pro for WordPress Support › Combine category and taxonomy
This topic contains 2 replies, has 2 voices, and was last updated by lorenz 5 years, 8 months ago.
- AuthorPosts
- January 10, 2019 at 7:00 pm #20704
I have a category named “betreuung”
And I have a taxanomy named “betreuung”
So, when I search for “betreuung” I get two (identical) lines for the results. See attached screen shot (first 2 lines):
– Betreuung (119)
– Betreuung (27)My customer, however, only wants so see one line;
– Betreuung (146)I tried hard to solve this but did not succeed.
Can you please help me with this?
Thanks a lot,
Regards
Lorenz
(Germany)Attachments:
You must be logged in to view attached files.January 11, 2019 at 2:19 pm #20712Hi!
Well, this could get really difficult, as each taxonomy term is probably linking to a different location. I have put together small code snipptet, that will try to group the terms by name during the post process.
Try adding this custom code to the functions.php in your theme/child theme directory (copy from line 3 only!). Before editing, please make sure to have a full site back-up just in case!add_filter('asp_results', 'asp_group_terms', 10, 1); function asp_group_terms($results) { $terms = array(); $terms_occurence = array(); $new_results = array(); foreach($results as $k=>&$r) { if ( isset($r->taxonomy) ) { preg_match('/^(.*?)\((.*?)\)/', $r->title, $m); if ( isset($m[1], $m[2]) ) { $terms[$m[1]] = isset( $terms[$m[1]] ) ? $terms[$m[1]] + $m[2] : $m[2]; } } } foreach($results as $k=>&$r) { if ( isset($r->taxonomy) ) { preg_match('/^(.*?)\((.*?)\)/', $r->title, $m); if ( isset($m[1], $m[2]) ) { // Already occured once, reset it if ( !isset($terms_occurence[$m[1]]) ) { $r->title = $m[1] . '(' . $terms[$m[1]] . ')'; $new_results[] = $r; $terms_occurence[$m[1]] = true; } } else { $new_results[] = $r; } } else { $new_results[] = $r; } } return $new_results; }
Please note, that this might not work in each and every case though.
Best,
Ernest Marcinko
If you like my products, don't forget to rate them on codecanyon :)
January 11, 2019 at 5:26 pm #20715Thank you so much for your support. This is much more support than I have expected!
I will let you know, how it works.Thanks,
Lorenz
(Germany) - AuthorPosts
You must be logged in to reply to this topic.