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]

Bud Parr
  • 179
  • 4
  • 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 00: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 05: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 Answers2

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

carlcs
  • 36,220
  • 5
  • 62
  • 139
0

Think it should be:

search: {
  attribute: {
    'keywords', 
    'body', 
    'title'
  }
},