Home › Forums › Product Support Forums › Ajax Search Pro for WordPress Support › Grouping when using filter asp_results
This topic contains 1 reply, has 2 voices, and was last updated by Ernest Marcinko 8 years ago.
- AuthorPosts
- March 20, 2015 at 9:45 am #4278
Hi there,
I have a little problem with the grouping option combined with the filter
asp_results
.
I use that filter to change the link of a custom post type to the related product like this. It works great.
https://gist.github.com/jacquesletesson/c50fdd9338aa58e995a2
However, when I turned on the grouping option it returns me a undefined element like on the screenshot.
Do you have any idea how I could fix that issue?
Thanks in advance for the support.
Best,
J.
-
This topic was modified 8 years ago by
Jacques Letesson.
-
This topic was modified 8 years ago by
Jacques Letesson.
Attachments:
You must be logged in to view attached files.March 20, 2015 at 11:07 am #4282Hi!
It’s because the grouped results structure is a bit different. I quickly put together a working snippet on how to handle grouped and non grouped results:
add_filter('asp_results','filter_asp_results'); function filter_asp_results($results){ /* If the results are grouped */ if (isset($results['grouped'])) { foreach ($results['items'] as $i_k=>$data) { if ($i_k == 'name') continue; // $result['data'] holds the results here foreach($results['items'][$i_k]['data'] as $r_k=>$res) { // let's make it easier to access a result $result = &$results['items'][$i_k]['data'][$r_k]; // changes are need to be made to the $result variable to take effect here $result->title = "xyz"; //test example /* Your code here */ } } /** * You need to return the $results variable here, * since the changes are made directly **/ return $results; /* Non-grouped */ } else { foreach($results as $k => $result) { $result = &$results[$k]; $result->title = "xyz"; //test example /* Your code here */ } } }
I think if you read through the comments you will understand 😉
Best,
Let me know if you need more help!
Ernest Marcinko
If you like my products, don't forget to rate them on codecanyon :)
-
This topic was modified 8 years ago by
- AuthorPosts
You must be logged in to reply to this topic.