Grouping when using filter asp_results

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 Ernest Marcinko 8 years ago.

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #4278
    Jacques Letesson
    Jacques Letesson
    Participant

    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.

    Attachments:
    You must be logged in to view attached files.
    #4282
    Ernest Marcinko
    Ernest Marcinko
    Keymaster

    Hi!

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

    Best,
    Ernest Marcinko

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


Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.