Submitted by admin on Fri, 08/30/2019 - 15:52
Image removed.

One Soft Decoder 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:

Image removed.
  • Go to Structure > Views > Create new view.
  • Choose to Show "Content".
  • The other settings you can choose according to your needs.
Image removed.
  • Under the "Advanced" tab on the right-hand side, click "Add" next to "Relationships":
Image removed.
  • Search for and choose the "Content: Author" relationship.
  • Click "Apply (All displays)" twice to save the relationship.
Image removed.
  • On the left-hand side, under Filter Criteria, click "Add".
Image removed.
  • Search for and choose "User: Name (raw)".
  • Click "Apply (All displays)".
Image removed.
  • Check the box, "Expose this filter to visitors, to allow them to change it".
  • Click "Apply (All displays)".
Image removed.
  • 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:
Image removed.

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.

Image removed.
Solutions Img