<p>You could use the Twig functions <code>merge</code> and <code>default</code> to merge the two sets of entries.</p>

<pre><code>{% set entries = craft.entries.search(query).order('score')|default([]) %}
{% set authors = craft.users.search('fullName:*' ~ query ~ '*')|default([]) %}

{% if authors %}
    {% set results = entries|merge(authorArticles) %}
{% endif %}

&lt;p&gt;
    You have {{ results|length }} {{ results|length == 1 ? 'result' : 'results' }}.
&lt;/p&gt;
</code></pre>

<p>The <code>default</code> function is a handy stand-in for short circuit evaluation in twig, so that you can be sure to at least pass an empty array to <code>merge</code>.</p>

CC BY-SA 3.0
2014-11-30T21:34:59.997Z
2014-11-30T21:34:59.997Z
Brian Whitton
<p>I've got a site-wide search box (based on the example in the documentation). It's doing a good job of searching through the entries, but is there a way that I can include a search through a user group like authors as well and include it in the same list of results? </p>

<p>Currently I just have this but its not getting any results for author searches even though I know they exist. It seems like the authors should be searchable since they're linked to the entry...</p>

<pre><code>{% set entries = craft.entries.search(query).order('score') %}
</code></pre>

<p>If I did another search through <code>craft.users.search</code> I could get another list of results, but I'd like to have one combined list. Is something like that possible?</p>

<users><search><author>
Including author in search for entries
# Including author in search for entries

(Asked by: username_0 on 2014-11-05)

I've got a site-wide search box (based on the example in the documentation). It's doing a good job of searching through the entries, but is there a way that I can include a search through a user group like authors as well and include it in the same list of results? 
Currently I just have this but its not getting any results for author searches even though I know they exist. It seems like the authors should be searchable since they're linked to the entry...
{% set entries = craft.entries.search(query).order('score') %}

If I did another search through craft.users.search I could get another list of results, but I'd like to have one combined list. Is something like that possible?

**Tags:** users, search, author


---

## 1 answers

### Answer by username_1 on 2014-11-30. Score: 3 | Accepted answer

You could use the Twig functions merge and default to merge the two sets of entries.
{% set entries = craft.entries.search(query).order('score')|default([]) %}
{% set authors = craft.users.search('fullName:*' ~ query ~ '*')|default([]) %}

{% if authors %}
    {% set results = entries|merge(authorArticles) %}
{% endif %}


    You have {{ results|length }} {{ results|length == 1 ? 'result' : 'results' }}.


The default function is a handy stand-in for short circuit evaluation in twig, so that you can be sure to at least pass an empty array to merge.


---

