Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

limit drupal view to show only nodes created by user

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

like image 928
siiva33 Avatar asked May 02 '11 11:05

siiva33


2 Answers

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

like image 143
enkara Avatar answered Sep 28 '22 07:09

enkara


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

like image 26
HEDMON Avatar answered Sep 28 '22 07:09

HEDMON