Craft CMS Asked by aslamdoctor on September 4, 2021
I want to do a search query so the product title or product tag name matches the keyword. below is my code. if I remove the tag related query, this code works as it looks into the product title only and returns the result. But how to make it work so it looks for the keyword in both product title and tag name? and if it exists in any one, it results specific records?
{% set productValues = {
keywords: craft.app.request.getParam('keywords'),
orderBy: craft.app.request.getParam('order') ? craft.app.request.getParam('order') : 'score'
} %}
{% set tag = craft.tags.search(craft.app.request.getParam('keywords')).first() %}
{% set productParameters = {
search: 'title:' ~ productValues.keywords,
relatedTo: [
'OR',
tag
],
orderBy: productValues.order
}%}
I think you need to make two separate queries, get two arrays, combine them using the merge
method and leave them unique, since these are different searches, textual and by related elements. It's like a quick fix, if I find something I will answer.
Answered by Pavel Pavlovich on September 4, 2021
Get help from others!
Recent Answers
Recent Questions
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP