<p>Try this:</p>

<pre><code>{# First, grab the username from the URI #}
{% set username = craft.request.segment(2) %}

{# Then, grab the user based on the username %}
{% set user = craft.users.username(username).first() %}

{# Make sure we actually found a user #}
{% if user %}
    {% set blogPosts = craft.entries.section('blog').authorId(user.id).find() %}

    Found: {{ blogPosts|length }} blog posts.
{% endif %}
</code></pre>

CC BY-SA 3.0
2014-07-03T16:32:53.860Z
Thanks for the reply Brad. The first part is working with a bit of modification `{% set user = craft.users.username(craft.request.segment(2)).first() %}`; `{{ user }}` returns the correct value, however when added to `.relatedTo()` it doesn't return any results (should in this case have 2 entries returned).
Ryan Shrum
CC BY-SA 3.0
2014-07-03T16:35:02.440Z
Try your 2nd example, then, with a slight modification to field {% set blogPosts = craft.entries.section('blog').relatedTo({ targetElement: user, field: 'authorId' })%}
Brad Bell
CC BY-SA 3.0
2014-07-03T16:53:37.183Z
That didn't work either. I tried a few different iterations of the same line: `{ targetElement: user, field: authorId }` `{ targetElement: user.id, field: authorId }` `{ targetElement: userd, field: 'authorId' }` `{ targetElement: user.id, field: 'authorId' }` You get the idea.
Ryan Shrum
CC BY-SA 3.0
2014-07-03T17:08:57.183Z
Check the latest edit.  Actually tested this one. :)
Brad Bell
CC BY-SA 3.0
2014-07-03T17:12:13.157Z
Now we're in business! Thanks for that. I guess I'll have to install the Happy Brad plugin now... -sigh-
Ryan Shrum
CC BY-SA 3.0
2014-07-03T17:13:13.403Z
Only happy when I'm drunk and my current status is sadly, very sober.
Brad Bell
CC BY-SA 3.0
2017-10-31T16:21:58.717Z
@BradBell is there a way to get around authors not showing up because they are not yet `verified`?
nihiser
CC BY-SA 3.0
2014-07-03T16:23:08.843Z
2014-07-03T17:06:35.370Z
2014-07-03T17:06:35.370Z
Brad Bell
<p>I'm returning the username as the second segment <code>/blog/username</code> and then setting the <code>username</code> var to <code>craft.request.segment(2)</code>.</p>

<p>I'm looking to list a group of entries by that author (username). I've tried:</p>

<pre><code>{% set blogPosts = craft.entries.section('blog').relatedTo(username) %}
</code></pre>

<p>I've also tried this:</p>

<pre><code>{% set blogPosts = craft.entries.section('blog').relatedTo({ targetElement: username, field: 'author' })%}
</code></pre>

<p>Anyone have a way to list through entries related by author?</p>

<entries><users><author>
How do I list entries from a single author?
# How do I list entries from a single author?

(Asked by: username_0 on 2014-07-03)

I'm returning the username as the second segment /blog/username and then setting the username var to craft.request.segment(2).
I'm looking to list a group of entries by that author (username). I've tried:
{% set blogPosts = craft.entries.section('blog').relatedTo(username) %}

I've also tried this:
{% set blogPosts = craft.entries.section('blog').relatedTo({ targetElement: username, field: 'author' })%}

Anyone have a way to list through entries related by author?

**Tags:** entries, users, author

---

## 1 answers

### Answer by username_1 on 2014-07-03. Score: 8 | Accepted answer

Try this:
{# First, grab the username from the URI #}
{% set username = craft.request.segment(2) %}

{# Then, grab the user based on the username %}
{% set user = craft.users.username(username).first() %}

{# Make sure we actually found a user #}
{% if user %}
    {% set blogPosts = craft.entries.section('blog').authorId(user.id).find() %}

    Found: {{ blogPosts|length }} blog posts.
{% endif %}

> **Comments:**
> **username_0**: Thanks for the reply Brad. The first part is working with a bit of modification `{% set user = craft.users.username(craft.request.segment(2)).first() %}`; `{{ user }}` returns the correct value, however when added to `.relatedTo()` it doesn't return any results (should in this case have 2 entries returned).  
> **username_1**: Try your 2nd example, then, with a slight modification to field {% set blogPosts = craft.entries.section('blog').relatedTo({ targetElement: user, field: 'authorId' })%}  
> **username_0**: That didn't work either. I tried a few different iterations of the same line: `{ targetElement: user, field: authorId }` `{ targetElement: user.id, field: authorId }` `{ targetElement: userd, field: 'authorId' }` `{ targetElement: user.id, field: 'authorId' }` You get the idea.  
> **username_1**: Check the latest edit.  Actually tested this one. :)  
> **username_0**: Now we're in business! Thanks for that. I guess I'll have to install the Happy Brad plugin now... -sigh-  
> **username_1**: Only happy when I'm drunk and my current status is sadly, very sober.  
> **username_2**: @BradBell is there a way to get around authors not showing up because they are not yet `verified`?  

---

