1

Is there any way of searching both entries and products at the same time? Wanting a single search on the site which will return all entries and products containing the searched for phrase.

Looked at combining the results from craft.entries.search() and craft.products.search() but this stops us from using pagination which we would like to have. Anybody got a solution or suggestions?

Would prefer not to split into 2 search pages if possible. Thank you.

2 Answers 2

2

Ended up creating a custom plugin to achieve this functionality. Also added some custom pagination logic. Set up a gist showing the variable and service files of the plugin as well as an example twig template to output the results.

https://gist.github.com/matt-adigital/e79b2fd2e14327b3f306a907f4e7e02e

All working well but it would be great if this was in core or just a little easier to implement. If we could leverage Crafts pagination for our own usage by passing in a dataset instead of being confined to the craft\elements\db\ElementQueryInterface object, then this would be a big help.

Another option could be to allow craft\elements\db\ElementQuery to accept multiple elementTypes or a null value, tried to submit with null but it is in fact required to be a string.

Hopefully anyone else who wants to use this functionality without going down the Algolia route will find this helpful.

1
  • Nice, just what I am looking for! But how add this as a plug-in? Or must this snippet added as an module? And is this snippet for craft 3 and commerce 2? Aug 27, 2019 at 13:07
1

Unfortunately you would need to do 2 element query searches and combine the results on the front end.

Most developers tend to go for https://algolia.com when they want fast advanced search, including searching across elements.

Probably easiest to get started by searching for an Algolia plugin in the plugin store. I only know https://github.com/Rias500/craft-scout for Craft 3 at the moment.

1
  • Thank you for your response Luke. Would be nice to have a built in function for this in the future if possible. Combining on the front end seems like it would cause pagination issues. Now that I know there is nothing available in core though I might try to throw together a plugin to achieve this. Trying to avoid adding any additional monthly costs such as Algolia for this client. Thanks again. Dec 7, 2018 at 11:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.