I have a vacancy's website which has a couple of search forms spread around the website. The craft standard search form works great, the only problem is I need to search only by the title field instead of all the content in the entries.

So my question is..

Is it possible to search only by title field?


Give this a go:

{% set searchTerm = craft.request.getParam('q') %}    
{% set query = craft.entries({
        search: 'title:*' ~ searchTerm ~ '*',
        limit: 5,
        locale: craft.locale,
        order: 'score'
    }) %}

You can leave out the * on both sides if you only want to search for full word matches. Also, this might help you take it further: https://craftcms.com/docs/searching

  • That did the trick. Couldn't figure it out straight from the docs though. May 5 '17 at 12:10

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.