Empty search with taxonomy filter not working properly

Home Forums Product Support Forums Ajax Search Pro for WordPress Support Empty search with taxonomy filter not working properly

This topic contains 16 replies, has 2 voices, and was last updated by ilariaroglieri ilariaroglieri 7 years, 11 months ago.

Viewing 2 posts - 16 through 17 (of 17 total)
  • Author
    Posts
  • #8722
    Ernest Marcinko
    Ernest Marcinko
    Keymaster

    Hi!

    I think I might have a solution, at least it’s working on my test environment.

    Basically you need to put these into your active theme folder, into the functions.php file:

    add_filter('asp_pagepost_results', 'asp_reorder_by_meta', 1, 1); 
    
    function asp_reorder_by_meta( $results ) {
      // first, get the missing CF field
      foreach ($results as $k => $r) {
        $results[$k]->m_author_name = get_post_meta($r->id, 'author_name', true);
      }
      // sorting by the new field with a helper funtion
      usort($results, "asp_meta_author_cmp");
      
      return $results;
    } 
    
    /**
     * Performs object attribute comparison
     */ 
    function asp_meta_author_cmp($a, $b) {
        return strcmp($a->m_author_name, $b->m_author_name);
    }

    This does the following:
    – Connects to ajax search pro via the “asp_pagepost_results” filter
    – then gets the “author_name” meta and adds it to the m_author_name field to each result item
    – performs a sorting based on a function, comparing the m_author_name fields, which now contains the author name custom field

    I hope this helps.

    Best,
    Ernest Marcinko

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


    #8724
    ilariaroglieri
    ilariaroglieri
    Participant

    It works like a charm!
    Thank you very much Ernest.
    Looking forward to the update!
    Ilaria

Viewing 2 posts - 16 through 17 (of 17 total)

You must be logged in to reply to this topic.