Reply To: 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 Reply To: Empty search with taxonomy filter not working properly

#8722

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 :)