1

Craft Pro 2.5.2761 (no plugins)

I've got a basic search form, and on my results template, the following:

{% set query = craft.request.getParam('q') %}

{% set articles = craft.entries({
section: 'article',
order: 'score',
search: {
  attribute: 'keywords',
  query: query,
  subLeft: true,
  subRight: true
}
}) %}

Which works as expected (I get results when the query term matches the keyword of an entry).

However, I want my search to encompass not just keywords, but also the title and the body field.

[edit - deleted part of my post because it was misleading as to the real problem]

3
  • You're using the object syntax, which expects key-value pairs {% set var = {'key1': 'value1', 'key2': 'value2'} %}. Try this to set an array {% set var = ['value1', 'value2'] %}, but I don't actually expect this to work. See my answer below. – carlcs Feb 10 '16 at 0:30
  • You're right, on both counts. I had tried that (only posted the last thing I tried, in desperation), and it didn't work, as you thought. – Bud Parr Feb 10 '16 at 5:01
  • Now that you modified your question, it's probably a dupe of the one I linked to above. I hope you find the new answer I just posted to it helpful. – carlcs Feb 10 '16 at 17:09
2

It doesn't look like it's possible to pass an array of attributes to the attribute parameter, the Craft docs explicitly state that it expects a string.

https://craftcms.com/docs/config-settings#defaultSearchTermOptions

0

Think it should be:

search: {
  attribute: {
    'keywords', 
    'body', 
    'title'
  }
},
1
  • Unfortunately, no. That returns the same error. There are other key/value pairs. – Bud Parr Feb 9 '16 at 21:15

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