Use Views to Show Content Created by Drupal Users
For example, the admins wanted to see all the articles written by a particular user, or all the orders they made in the store.
I’m going to make this happen by creating a search page using Views.
First, make sure that users are associated with your content, as in the example below:
- Go to Structure > Views > Create new view.
- Choose to Show “Content”.
- The other settings you can choose according to your needs.
- Under the “Advanced” tab on the right-hand side, click “Add” next to “Relationships”:
- Search for and choose the “Content: Author” relationship.
- Click “Apply (All displays)” twice to save the relationship.
- On the left-hand side, under Filter Criteria, click “Add”.
- Search for and choose “User: Name (raw)”.
- Click “Apply (All displays)”.
- Check the box, “Expose this filter to visitors, to allow them to change it”.
- Click “Apply (All displays)”.
- Save your view.
- Visit the view on the front of your site, and you should be able to search for users’ content, using the exposed filter:
Pro tip: inside the View, set “Use Ajax” to “Yes” under the “Advanced” tab on the right-hand side. This will allow the search to load without refreshing the whole page.
Hi Steve,
Good information here – I found this page by Googling for another, similar thing I’m trying to do. I want to have a view that shows all of the bloggers on my site (I have a role called “Blogger”). That is pretty easy to do. Now, I want to be able to have a link for each blogger that would display a view containing all of their Blog Posts (that’s a content type). I can, of course, add a relationship to the view, but that would make each blog post’s title (for example) be included right on the page, but that’s not what I want.
Drupal 8 if it makes a difference.
Hi John
Our support is mostly for our members: [url=https://www.ostraining.com/support-forum/recent/]https://www.ostraining.com/…[/url] (this tutorial was written for a member), so that’s where the detailed answers are.
The solution probably lies in the “Rewrite Results” options of the fields in Views. On the main page you can have a “Read all this users’s post” link and send that to the individual views.
Hi Steve,
Sorry – I didn’t realise that it was a member site – I guess I should actually poke around before butting in 🙂
Thanks for the hint – creating a view showing blog entries with a contextual filter for the username and then putting a link in the blogroll with Rewrite Results, as you suggested, works just fine.
Thanks for the hint.
@johnstegeman No worries. Large parts of our site are public and we’re happy to answer questions in the comments.
Glad to hear it worked.
As a paid member I can say it’s totally worth it 🙂
Thanks Chrys!