Answer the question
In order to leave comments, you need to log in
How to sort AJAX search results correctly?
Hello.
We did an AJAX search for products on the site. We encountered such a problem that when entering a short word (for example, spruce), which is found in the names of other products, other products are displayed first, and only then only "Firs". The search was done on this lesson
For clarity of the situation.
Is it possible to first display products with a complete match at the beginning of the product, and only then all the rest?
How we are sampling now:
$arg = array(
'post_type' => array('product'),
'orderby'=> array('type'=>'DESC', 'title'=>'ASC'),
'post_status' => 'publish',
'product_cat' => $category,
's' => convert_english_letters($_POST['s']),
'meta_query' => array(
array(
'key' => '_stock_status',
'value' => 'instock'
)
)
);
Answer the question
In order to leave comments, you need to log in
blues not only ate, but also drank (c)
the easiest way is to write to the author of the module or hire a freelancer
In general, there are several solutions, as always.
You need to make 2 queries to the database on the server. One - exclusively for a phrase starting with "Spruce", the other for searching for a phrase anywhere.
To do this, take a look at the workings and class arguments WP_Query
. It has a hook posts_clauses_request
where you can tweak the relevant part of the request.
Another solution is to delete standalone SQL queries in the database. Then you will have full control in your hands, but you will have to deal with caching issues (this is optional)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question