Forum Replies Created
-
AuthorPosts
-
Ernest Marcinko
KeymasterYou cannot access this content.
June 26, 2023 at 3:50 pm in reply to: Results suggestions – how to add more than post tile in the results #44449Ernest Marcinko
KeymasterHi,
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$resultsarray (it will basically do nothing I believe), and then will try to sort the$scoresarray too with the same ordering as the$resultsarray. 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.
Ernest Marcinko
KeymasterHi Michael,
Thank you for the details!
The unwanted items in the search were from the taxonomy
gresys_tag, which I disabled for you here. Those options are to return the taxonomy terms as results, and you don’t want that in your case.Now if you check the filters the items should be filtered correctly and the unwanted tags will no longer be displayed.
Ernest Marcinko
KeymasterYou cannot access this content.
Ernest Marcinko
KeymasterYou cannot access this content.
Ernest Marcinko
KeymasterThank you, that worked!
I checked the configuration, and I changed this option for you.
The results were seemingly not changing as those items were also displayed, which were not associated with the taxonomies. Now it should be all right.Ernest Marcinko
KeymasterYou cannot access this content.
Ernest Marcinko
KeymasterIt’s likely only the date format and the field. I checked to see and you seem to be using the Events Manager plugin, for that this should work:
add_filter("asp_query_args", "asp_query_args_apply_date", 10, 2); function asp_query_args_apply_date($args, $search_id) { $args['post_meta_filter'][] = array( 'key' => '_event_start', 'value' => date('Y-m-d H:i:s'), 'operator' => '>=', 'allow_missing' => false ); return $args; }Ernest Marcinko
KeymasterYou cannot access this content.
Ernest Marcinko
KeymasterHi!
Thank you for your kind words!
Surely it is possible, but you may need a few lines of code for it. I am not exactly sure about the plugin you are using for events, but I have constructed a custom code snippet, which should do exactly that if the date format is what I think it is. You will find it below.
Try adding this code via the Code Snippets plugin or to the functions.php file in your theme/child theme directory – make sure to have a full server back-up first for safety. For more details you can check the safe coding guidelines.
add_filter("asp_query_args", "asp_query_args_apply_date", 10, 2); function asp_query_args_apply_date($args, $search_id) { $args['post_meta_filter'][] = array( 'key' => '_event_start_date', 'value' => date('Y-m-d'), 'operator' => '>=', 'allow_missing' => false ); return $args; }Ernest Marcinko
KeymasterYou cannot access this content.
Ernest Marcinko
KeymasterHi,
Thank you for the details!
The list only displays the first post type name associated, it is a visual thing only, it will still apply to all post types assigned with the taxonomy, you don’t have to worr about that.
I tried to log-in to quicky look at the settings, but the username/password is not working unfortuantely. Can you please check that?
The post type filter seems to be working okay, that is a very good sign, so this is very likely only a minor misconfiguration.Ernest Marcinko
KeymasterYou cannot access this content.
Ernest Marcinko
KeymasterYou cannot access this content.
Ernest Marcinko
KeymasterYou cannot access this content.
-
AuthorPosts