<p>Yes, you can change both the columns to be selected and execute queries in several ways to get the results in different formats. In this case, you want to use <code>select()</code> to select the <code>title</code> column and execute the query with <code>column()</code> to get an array of titles instead of an array of <code>Entry</code> objects.</p>
<pre class="lang-twig prettyprint-override"><code>{% set entryTitles = craft.entries()
    .select('title')
    .column()
%}
</code></pre>
<p>Check out the documentation on <a href="https://craftcms.com/docs/3.x/element-queries.html#advanced-element-queries" rel="nofollow noreferrer">Advanced Element Queries</a> for details.</p>
<p>If you want to select multiple columns at once, you can use <a href="https://craftcms.com/docs/3.x/entries.html#asarray" rel="nofollow noreferrer"><code>asArray</code></a> to  get an array of associative arrays instead of entry objects. Note that if you want to select custom fields (instead of native properties like <code>title</code>), you need to include both the field prefix and suffixes in the column name – see <a href="https://craftcms.stackexchange.com/q/38471/11705">this question</a> for details.</p>

CC BY-SA 4.0
2022-03-17T08:59:09.110Z
2022-03-17T08:59:09.110Z
MoritzLost
<p>@MoritzLost's answer should be the accepted one. But, as an alternative approach you could also use the <a href="https://twig.symfony.com/doc/2.x/filters/map.html" rel="nofollow noreferrer"><code>|map</code></a> Twig filter to &quot;prune&quot; the entry objects returned from a normal element query:</p>
<p>To create an array containing only entry titles:</p>
<pre><code>{% set entryTitles = craft.entries.all()|map(entry =&gt; entry.title) %}
</code></pre>
<p><strong>Edit</strong>: As suggested by MoritzLost in the comments, an even simpler way to retrieve an array of <em>single</em> values is by using the <a href="https://craftcms.com/docs/3.x/dev/filters.html#column" rel="nofollow noreferrer"><code>|column</code></a> filter:</p>
<pre><code>{% set entryTitles = craft.entries.all()|column('title') %}
</code></pre>
<p>To create an array of objects containing multiple values – for example, the title <em>and</em> a custom <code>heading</code> field:</p>
<pre><code>{% set entries = craft.entries.all()|map(entry =&gt; { title: entry.title, heading: entry.heading }) %}
</code></pre>
<p>Between the two approaches, using Advanced Element Queries to only fetch the column(s) that you need will probably be a bit faster - but unless this is a massive dataset, the actual difference is likely going to be completely negligible – while the big benefit with the <code>|map</code> (or <code>|column</code>) approach over Advanced Element Queries is that you won't have to worry about custom field prefixes or suffixes.</p>

CC BY-SA 4.0
2022-03-17T09:42:36.317Z
Good caveat – note that the first example can be simplified still using the [`column` filter](https://craftcms.com/docs/3.x/dev/filters.html#column): `{% set entryTitles = craft.entries.all()|column('title') %}`
MoritzLost
CC BY-SA 4.0
2022-03-18T07:11:27.217Z
Good call about the `column` filter for single values!
Mats Mikkel Rummelhoff
CC BY-SA 4.0
2022-03-17T09:10:11.543Z
2022-03-18T07:15:04.217Z
2022-03-18T07:15:04.217Z
Mats Mikkel Rummelhoff
<p>Can a return schema be specified for entry queries? I'd only like the titles instead of the whole entry.</p>

<query><elementquery>
Element query for specific fields
# Element query for specific fields

(Asked by: username_0 on 2022-03-17)

Can a return schema be specified for entry queries? I'd only like the titles instead of the whole entry.

**Tags:** query, elementquery

---

## 2 answers

### Answer by username_1 on 2022-03-17. Score: 3 | Accepted answer

Yes, you can change both the columns to be selected and execute queries in several ways to get the results in different formats. In this case, you want to use select() to select the title column and execute the query with column() to get an array of titles instead of an array of Entry objects.
{% set entryTitles = craft.entries()
    .select('title')
    .column()
%}

Check out the documentation on Advanced Element Queries for details.
If you want to select multiple columns at once, you can use asArray to  get an array of associative arrays instead of entry objects. Note that if you want to select custom fields (instead of native properties like title), you need to include both the field prefix and suffixes in the column name – see this question for details.


---

### Answer by username_2 on 2022-03-17. Score: 5

@MoritzLost's answer should be the accepted one. But, as an alternative approach you could also use the |map Twig filter to "prune" the entry objects returned from a normal element query:
To create an array containing only entry titles:
{% set entryTitles = craft.entries.all()|map(entry => entry.title) %}

Edit: As suggested by MoritzLost in the comments, an even simpler way to retrieve an array of single values is by using the |column filter:
{% set entryTitles = craft.entries.all()|column('title') %}

To create an array of objects containing multiple values – for example, the title and a custom heading field:
{% set entries = craft.entries.all()|map(entry => { title: entry.title, heading: entry.heading }) %}

Between the two approaches, using Advanced Element Queries to only fetch the column(s) that you need will probably be a bit faster - but unless this is a massive dataset, the actual difference is likely going to be completely negligible – while the big benefit with the |map (or |column) approach over Advanced Element Queries is that you won't have to worry about custom field prefixes or suffixes.

> **Comments:**
> **username_1**: Good caveat – note that the first example can be simplified still using the [`column` filter](https://craftcms.com/docs/3.x/dev/filters.html#column): `{% set entryTitles = craft.entries.all()|column('title') %}`  
> **username_2**: Good call about the `column` filter for single values!  

---

