Answers.Body: <p>You can just limit your search to those specific user fields.</p>
  <p>It should go something like:</p>
  <pre><code>{% set users = craft.users()
      .search('fullName:' ~ query ~ ' OR username:' ~ query)
      .group('creatives')
      .all() %}
  </code></pre>
  <p>More info on searching here: <a href="https://docs.craftcms.com/v3/searching.html#supported-syntaxes" rel="nofollow noreferrer">https://docs.craftcms.com/v3/searching.html#supported-syntaxes</a></p>
  <p><strong>Top tip:</strong> You can test your search query directly in the search bar within Craft's admin. e.g. See if <code>fullName:Tom OR username:Tom</code> pulls the intended results.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-06-17T11:17:24.447Z
Answers.Text: Awesome that seem's to work perfectly! I had something similar but it didnt work as expected first time around.
  
  Appreciate it
Answers.UserDisplayName: Tom Byrom
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-06-17T09:45:10.777Z
Answers.LastActivityDate: 2020-06-17T10:04:35.340Z
Answers.LastEditDate: 2020-06-17T10:04:35.340Z
Answers.UserDisplayName: dmatthams
Body: <p>I have the below. I want to only show results that contain the query in the the username or fullName attributes.</p>
  
  <p>Because currently if I search for say Tom the search results will return users without a username or full name containing the query Tom, but will show a person if the email contains it. I don't want this as emails are not publicly shown and therefore may cause confusion to the user searching. </p>
  
  <p>How would I exclude email from the search criteria or only allow searching from the username or fullName attribute?</p>
  
  <p>The same happens when searching entries - how do I narrow the search to only use the title field for example otherwise the search results can be too broad which is bad for UX.</p>
  
  <pre><code>{% set users = craft.users()
      .search(query)
      .group('creatives')
      .all() %}
  
  {% if users|length %}
      &lt;p&gt;{{users|length }} results:&lt;/p&gt;
  
      &lt;ul&gt;
          {% for user in users %}
             &lt;li&gt;&lt;a href="/people/{{ user.username }}"&gt;{{ user.username }}&lt;/a&gt;&lt;/li&gt;
          {% endfor %}
      &lt;/ul&gt;
  {% else %}
      &lt;p&gt;Your search for {{ query }} didn&amp;#39t return any users.&lt;/p&gt;
  {% endif %}
  </code></pre>
  
Tags: <search>
Title: How to search against a specific field/s, and not every field related to an element?
ThreadText: # How to search against a specific field/s, and not every field related to an element?
  
  (Asked by: username_0 on 2020-06-16)
  
  I have the below. I want to only show results that contain the query in the the username or fullName attributes.
  
  Because currently if I search for say Tom the search results will return users without a username or full name containing the query Tom, but will show a person if the email contains it. I don't want this as emails are not publicly shown and therefore may cause confusion to the user searching.
  
  How would I exclude email from the search criteria or only allow searching from the username or fullName attribute?
  
  The same happens when searching entries - how do I narrow the search to only use the title field for example otherwise the search results can be too broad which is bad for UX.
  
  ```
  {% set users = craft.users()
      .search(query)
      .group('creatives')
      .all() %}
  
  {% if users|length %}
      <p>{{users|length }} results:</p>
  
      <ul>
          {% for user in users %}
             <li><a href="/people/{{ user.username }}">{{ user.username }}</a></li>
          {% endfor %}
      </ul>
  {% else %}
      <p>Your search for {{ query }} didn&#39t return any users.</p>
  {% endif %}
  
  ```
  
  **Tags:** search
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2020-06-17. Score: 2 | Accepted answer
  
  You can just limit your search to those specific user fields.
  
  It should go something like:
  
  ```
  {% set users = craft.users()
      .search('fullName:' ~ query ~ ' OR username:' ~ query)
      .group('creatives')
      .all() %}
  
  ```
  
  More info on searching here: <https://docs.craftcms.com/v3/searching.html#supported-syntaxes>
  
  **Top tip:** You can test your search query directly in the search bar within Craft's admin. e.g. See if `fullName:Tom OR username:Tom` pulls the intended results.
  
  > **Comments:**
  > **username_0**: Awesome that seem's to work perfectly! I had something similar but it didnt work as expected first time around.  Appreciate it  
  
  ---
  
  