Home › Forums › Product Support Forums › Ajax Search Pro for WordPress Support › Results suggestions – how to add more than post tile in the results › Reply To: Results suggestions – how to add more than post tile in the results
Hi,
Before I start I need to inform you that I can’t promise anything as this falls way above the customization category and that is not officially part of our support. That being said I will of course try my best to get around this.
The code seems great to me, after the asp_results hook the plugin only executes a final results grouping function, but only if the results grouping feature is enabled, but in your case it is not. The order is not changed by the plugin afterwards.
In your code you do an array_multisort, however it does not seem correct to me, and also the $results array also contains the original results, it is not reset.
In your case the array_multisort will sort the $results array (it will basically do nothing I believe), and then will try to sort the $scores array too with the same ordering as the $results array. So it’s not doing what you think it’s doing.
Instead of that, add the score to one of the results attributes like so:
$result->score = $strpos_score !== false ? $strpos_score : INF, $levenshtein_score;
Then do a usort:
usort($results, function($a, $b){
if ( isset($a->score, $b->score) ) {
if ( $a->score == $b->score ) {
return 0;
}
return $a->score > $b->score ? -1 : 1;
} else {
if ( isset($a->score) ) {
return 1;
}
if ( isset($b->score) ) {
return -1;
}
}
return 0;
});
This one is pretty ugly, but it should be close to a possible solution.
As for your other question, unfortunately it is not possible to create multiple inputs for the same form. You can however create an input custom field filter. Then you can fetch the value of that filter from the $args[‘post_meta_filter’] argument.