I'm successfully listing user (authors) via search from the url, so

/author/Tom+Bowler lists data and entries by that name with

{% set getauth = craft.request.lastSegment %}
{% for authordetails in craft.users.search(getauth) %}

but we want to limit that search to 'fullName' (or what is best) ideally, as currently we are listing any authors not just the one that may mention "Tom Bowler" in their bio.

At what point, and how is best to filter down to that search?


There's a nice list in the Craft docs with lot of examples for supported search syntaxes. Here's two that probably do what you are after:

body:salty → where the ‘body’ field contains “salty”.
body::"salty dog" → where the ‘body’ field is set to “salty dog” and nothing more.

Combine it with your variable like so:

craft.users.search('fullName::"' ~ getauth ~ '"')
  • This is the one thanks. Works great. I did look at this, but can't have been getting the syntax exactly right. Sep 2 '14 at 6:02

What about not using the search parameter at all and use the lastName and firstName parameters instead (you wouldn't rely on up-to-date search indexes)?

{% set getauth = 'tom+bowler' %}

{% set fullName = getauth|split('+') %}
{% set lastName = fullName[1] %}
{% set firstName = fullName[0] %}

{% for authordetails in craft.users.lastName(lastName).firstName(firstName) %}
  • Tried this as well, but it didn't seem so happy. Appreciated! Sep 2 '14 at 6:07

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.