1

We're looking to pull entries from a channel that starts with a specific letter. We've tried using Craft's search option, with 'C*', to pull any title with a word that starts with C. However, it's pulling entries whose second or third words begin with C as well. Is there another route we should consider to achieve this result?

{% set myQuery = craft.entries.section('channelName').limit(null).search('title:C*').order('title') | group('title|first') %}
1

You're close! According to the entry on searching in the Craft docs, this should work:

{% set myQuery = craft.entries.section('channelName').limit(null).search('title::C*').order('title') | group('title|first') %}

Note the format of the search string with a double colon: title::C*.

1
  • Worked perfectly. Thanks @steve-rowling! I must have just overlooked this option in the list. Late night coding will do just that :)
    – Nick L.
    Aug 15 '16 at 13:17
1

Changing .search('title:C*') to .search('title::C*') appears to work, on my end – the :: essentially tells Craft that there shouldn't be anything in front of the "C".

Also, for this to work you need to not have enabled fuzzy search by default.

4
  • Thanks Mats. It does seem to be working though without any changes to our default fuzzy search setting.
    – Nick L.
    Aug 15 '16 at 13:19
  • Right, I meant that it works unless you've enabled default fuzzy searching, i.e. the vanilla defaultSearchTermOptions configuration will be fine. Poor wording on my part :) Aug 15 '16 at 13:24
  • I thought that might have been your intent :) Thanks again.
    – Nick L.
    Aug 15 '16 at 13:29
  • No worries @NickL. :) Aug 15 '16 at 13:29

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.