7
votes

I'm using drupal 7. I created a view for displaying nodes of a specific content type (e.g. products). When viewing the page, I want only those products displayed which were created by the user (currently shows all products).

I would like to do it without using a url filter so the url would be simply:

/myproducts

3

3 Answers

13
votes

Use the filter "User: Current". If that doesn't work, try with a relationship

7
votes

With the Advanced Help module you can see "Example to filter content by the current logged-in user": http:// yoursite /help/views/example-filter-by-current-user

And there said:

Creating the relationship

In order to have access to the author of the content, it is important to create a relationship between the current content type, and users.

Under Advanced in the right column, select add next to Relationships.

Select Content: Author and click on Add and configure relationships. Leave the settings as they are and click on Apply (all displays).

You now have access to the user data related to the content you are viewing.

Filtering the view

Now you need to filter the view to display only content authored by the current user. This >data is now available for the content because you have created the relationship in the step >above.

Next to Filter criteria click on add to add a new filter to your view.

Filter the list of fields by selecting User next to Filter at the top. You now have more >fields than before due to the relationship you created.

Select User: Current from the list and click on Add and configure filter criteria.

Since this field is only visible due to the relationship you created, author will already be selected under Relationship. This shows that the relationship you created is being used for the filter field.

Select Yes under Is the logged in user, and click on Apply (all displays).

If you have authored content of the type Blog Post, you should now see a list of those posts under the preview section at the bottom.

Saving & testing the view

2
votes

Here's what I used to make it work.

  1. Under relationships, add content:author
  2. Under contextual relationship, add user: authentication name and relationship: author (or whatever you called your relationship).

And if you want to be even more sure, add to filter: user current and add relationship.