17

In Drupal 6 you can have a filter node.uid = current user. How do you do this in Drupal 7?

22

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.

Screen shot

  • 1
    I've always used Relationships but will look at contexts too. View's is awesome. – Citricguy Feb 13 '12 at 12:08
  • Going to modify about 100 views. :) Thank you for the details @googletorp. – Citricguy Feb 13 '12 at 12:18
  • 1
    you 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 – george marcotte Feb 14 '12 at 2:45
18

You need to edit your view, go to the Advanced column (far right) and add a new relationship.

Add Relationship

You will specifically need to add the "Content: Author" relationship.

Next, under "Filters" you will need to add the "User: Current" filter.

Add Filter

Now you should be able to filter content owned by the currently logged in user.

  • 1
    While 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. – googletorp Feb 13 '12 at 12:13
  • This will save way more than a few ms on a bunch of my queries. :) Thank you for the clarification. – Citricguy Feb 13 '12 at 12:20
-2

you can add simply

"User: Current" in "Filter" criteria.

  • Not enough explanation here for people to follow – Ben Jan 17 '18 at 14:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.