In Drupal 6 you can have a filter node.uid = current user
. How do you do this in Drupal 7?
3 Answers
You need to add the filter as a "context" (Advanced) where you can supply a default argument. If you context is for a user, like the node author, then you can select stuff like id of logged in user.
-
1I've always used Relationships but will look at contexts too. View's is awesome. Commented Feb 13, 2012 at 12:08
-
Going to modify about 100 views. :) Thank you for the details @googletorp. Commented Feb 13, 2012 at 12:18
-
1you notice the first line of text in the context filter? "When the filter value is not in the URL" so I tried this already and it works if the url does not have a users id in it but if user a is looking at some user b profile then this view is going to use users b id not users a Commented Feb 14, 2012 at 2:45
You need to edit your view, go to the Advanced column (far right) and add a new relationship.
You will specifically need to add the "Content: Author" relationship.
Next, under "Filters" you will need to add the "User: Current" filter.
Now you should be able to filter content owned by the currently logged in user.
-
1While this work, this is slower than the using context filters, as you need to create a join. It's probably only a few ms slower, but no reason to waste resources. Commented Feb 13, 2012 at 12:13
-
This will save way more than a few ms on a bunch of my queries. :) Thank you for the clarification. Commented Feb 13, 2012 at 12:20
you can add simply
"User: Current" in "Filter" criteria.