1

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
 }%}
1

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.

| improve this answer | |
  • OK, thank you. I am not very good with craft cms, working on it for the first time, so no idea how to do the merge but I will take a look at documentation – aslamdoctor Jul 17 at 5:39

Your Answer

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

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