I don't want to ustilise the username or the ID of a user to get their profile info so I am using their first and last name. So far I can fetch the user based on first name:

{% set slug = 'first-last' %}
{% set firstNameSlug = slug|split('-')[0] %}
{% set lastNameSlug = slug|split('-')[1] %}

{% set user = craft.users.firstName(slug).first %}

How do I build on this code to fetch using the first name AND last name?

1 Answer 1


See: https://docs.craftcms.com/v3/dev/element-queries/user-queries.html#lastname

{% set slug = 'first-last'|split('-') %}
{% set firstNameSlug = slug[0] %}
{% set lastNameSlug = slug[1] %}

{% set user = craft.users.firstName(firstNameSlug).lastName(lastNameSlug).first %}

We only need to split once, so I spit the slug variable instead.

You were passing slug to the first name method, but you would want to pass firstNameSlug.

Alternately this can be written like this if you know the slug is correct:

{% set slug = 'first-last' %}
{% set user = craft.users.slug(slug).first %}

But you said you don't want to do that so I'll assume you know what you are doing.

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.