limit drupal view to show only nodes created by user

11,865

Solution 1

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

Solution 2

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

Solution 3

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.

Share:
11,865
siiva33
Author by

siiva33

Updated on June 04, 2022

Comments

  • siiva33
    siiva33 almost 2 years

    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

  • Pupil
    Pupil about 11 years
    The filter "User: Current" worked. You saved my half day. Thanks @enkara
  • Jim
    Jim almost 11 years
    If you're using Views 3 then you'll need to add a relationship in order to get the User: Current filter to appear: stackoverflow.com/questions/7420031/…
  • JohnnyJS
    JohnnyJS over 10 years
    it is automatically added.
  • Alex.Barylski
    Alex.Barylski over 10 years
    How do you factor in roles now? For instance I have a role called 'webmin' and this user of this role should be able to see everything but others limited to only their own content
  • enkara
    enkara over 10 years
    I haven't used drupal for more than two years now and I don't remember exactly, but I think I would have solved this making two different tabs in the view, with different permissions (just in case) and then a custom template that would show one view or the other depending on the role