Ok, so I ended up using Relevanssi. But with some changes.
First of all, filtering on taxonomies was pretty simple, since it was built into Relevanssi, all I had to do was change the names of my <select> elements to the names of the taxonomy + change the values โโto bullets:
<select name="custom_taxonomy"> <option value="some-term">Some term</option> ... </select>
Secondly, to sort by a custom field, I had to use the relevanssi_hits_filter filter. Unlike pre_get_posts or relevanssi_modify_wp_query (which Sheikh Khera kindly suggested), this filter receives an array of messages, not a WP_Query object. When I tried to use the WP_Query object, the order just didn't change. Here's basically how to make your own look using relevanssi_hits_filter :
<?php add_filter('relevanssi_hits_filter', 'h5b_hits_filter'); function h5b_hits_filter ($hits) { global $wp_query; if (isset($wp_query->query_vars['orderby']) and $wp_query->query_vars['orderby'] == 'price') { if (count($hits[0])) { usort($hits[0], 'h5b_sort_by_price'); } } return $hits; } function h5b_sort_by_price ($a, $b) { $priceKey = 'price'; $aPrice = get_post_meta($a->ID, $priceKey, true); $bPrice = get_post_meta($b->ID, $priceKey, true); $aPrice = $aPrice ? $aPrice : 10000000; $bPrice = $bPrice ? $bPrice : 10000000; if ($aPrice == $bPrice) { return 0; } return ($aPrice < $bPrice) ? -1 : 1; }
It also helped with a previous problem that I had in that messages that did not have a price key were not displayed in the search results. Now they do, and the reason I give them the price of "10,000,000" is because they appear after those who have a price.
Finally, I also needed an empty search . According to Relevanssi dev, this is only supported in the Premium version, but I think I managed to get around this. At first I got WP to display the search page, even if? S was empty:
<?php add_filter('request', 'h5b_allow_empty_search'); function h5b_allow_empty_search ($qryVars) { if (isset($_GET['s']) and empty($_GET['s'])) { $qryVars['s'] = ' '; } return $qryVars; }
Secondly, I told Relevanssi to get all the messages if? s was empty, by default it will not receive any records at all. Unfortunately, the default behavior with custom taxonomies stopped working (my code wrote it), so I had to manually check the taxonomy in this code:
<?php add_filter('relevanssi_hits_filter', 'h5b_allow_empty_search_filter'); function h5b_allow_empty_search_filter ($hits) { if (isset($_GET['s']) and empty($_GET['s']) and !count($hits[0])) { $taxQry = array('relation' => 'AND'); if (!empty($_GET['custom_taxonomy'])) { $taxQry[] = array( 'taxonomy' => 'custom_taxonomy', 'field' => 'slug', 'terms' => $_GET['custom_taxonomy'] ); } $args = array( 'numberposts' => -1, 'post_type' => 'any' ); if (count($taxQry) > 1) { $args['tax_query'] = $taxQry; } $hits[0] = get_posts($args); } return $hits; }
What is it. Everything seems to work, and hopefully this helps someone who has similar queries in the future.
I really hope WP improves its ridiculous search in the future. Sorting by relevance should be what is available in the world, the most popular CMS imo.
Thanks to @Sheikh Heera for pointing me in the right direction. I am not sure who should give the correct answer, although I saw how I really could not use the material that you proposed.