Reply To: Grouping when using filter asp_results

Home Forums Product Support Forums Ajax Search Pro for WordPress Support Grouping when using filter asp_results Reply To: Grouping when using filter asp_results

Ernest Marcinko
Ernest Marcinko


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:

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 😉
Let me know if you need more help!

Ernest Marcinko

If you like my products, don't forget to rate them on codecanyon :)