This website uses cookies to personalize your experience. By using this website you agree to our cookie policy.

Grouping when using filter asp_results

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

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

    Hi there,

    I have a little problem with the grouping option combined with the filter [code]asp_results[/code].

    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.

    #4282
    Ernest MarcinkoErnest 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:

    [code]
    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 */
    }
    }
    }
    [/code]

    I think if you read through the comments you will understand 😉
    Let me know if you need more help!

Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.