Upgrade Your Drupal Skills

We trained 1,000+ Drupal Developers over the last decade.

See Advanced Courses NAH, I know Enough

Use Views to Show Content Created by Drupal Users

Parent Feed: 
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

About the author

Steve is the founder of OSTraining. Originally from the UK, he now lives in Sarasota in the USA. He was a teacher for many years before starting OSTraining. Steve wrote the best-selling Drupal and Joomla books.


Author: 
Original Post: 

About Drupal Sun

Drupal Sun is an Evolving Web project. It allows you to:

  • Do full-text search on all the articles in Drupal Planet (thanks to Apache Solr)
  • Facet based on tags, author, or feed
  • Flip through articles quickly (with j/k or arrow keys) to find what you're interested in
  • View the entire article text inline, or in the context of the site where it was created

See the blog post at Evolving Web

Evolving Web