Use Views to Show Content Created by Drupal Users

Use Views to Show Content Created by Drupal Users
Use Views to Show Content Created by Drupal Users

One SoftD 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