Use Views to Show Content Created by Drupal Users

Use Views to Show Content Created by Drupal Users
One OSTraining member wanted to allow site admins to show the content created by different 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:

List of Drupal content with authors
  • Go to Structure > Views > Create new view.
  • Choose to Show “Content”.
  • The other settings you can choose according to your needs.
Creating a Drupal view to show content
  • Under the “Advanced” tab on the right-hand side, click “Add” next to “Relationships”:
Adding a relationship in Drupal views
  • Search for and choose the “Content: Author” relationship.
  • Click “Apply (All displays)” twice to save the relationship.
choose the "Content: Author" relationship in Drupal views
  • On the left-hand side, under Filter Criteria, click “Add”.
Add a Filter Criteria in Drupal Views
  • Search for and choose “User: Name (raw)”.
  • Click “Apply (All displays)”.
Choose "User: Name (raw)" in Drupal views
  • Check the box, “Expose this filter to visitors, to allow them to change it”.
  • Click “Apply (All displays)”.
Exposing a Drupal filter to visitors
  • 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:
A completed Drupal view showing content per user

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.

Use Ajax in Drupal Views

Author

  • Steve Burge

    Steve is the founder of OSTraining. Originally from the UK, he now lives in Sarasota in the USA. Steve's work straddles the line between teaching and web development.

    View all posts
0 0 votes
Article Rating
Subscribe
Notify of
guest

6 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
John Stegeman
John Stegeman
8 years ago

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.

steve
steve
8 years ago
Reply to  John Stegeman

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.

John Stegeman
John Stegeman
8 years ago
Reply to  steve

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.

steve
steve
8 years ago
Reply to  John Stegeman

@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.

chrys
8 years ago
Reply to  John Stegeman

As a paid member I can say it’s totally worth it 🙂

steve
steve
8 years ago
Reply to  chrys

Thanks Chrys!

6
0
Would love your thoughts, please comment.x
()
x