The DirectoryBox theme by ChimpGroup has a heavily customized search function that searches its own custom post type, 'listings'.

Search results are returned in seemingly random order when I specify that the query order by relevance.

What I need is to sort the results so that listings that have a match in their name are returned first, followed by results with matches in the description and other fields.

For example, if the search term is 'blue', then I need places named things like 'Blue Anchor' and 'California Blue' to be returned first, followed by listings that don't have the word 'blue' in the name but might perhaps have a description like 'Beautiful views of the most blue ocean you'll ever see'.

I've got the idea that I should be able to add a property to the items in the collection of returned search results, based on whether their name matches the search term, and then sort on that property, to get the results in the order I need. The only problem is I have no idea how to alter the query results in this way. If anyone can offer any assistance I would be very grateful.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.