Take the 2-minute tour ×
Craft CMS Stack Exchange is a question and answer site for administrators, end users, developers and designers for Craft CMS. It's 100% free, no registration required.

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?

share|improve this question

2 Answers 2

up vote 2 down vote accepted

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 ~ '"')
share|improve this answer
    
This is the one thanks. Works great. I did look at this, but can't have been getting the syntax exactly right. –  Simon Clayson Sep 2 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) %}
share|improve this answer
    
Tried this as well, but it didn't seem so happy. Appreciated! –  Simon Clayson Sep 2 at 6:07

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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