2

How to do I create a filter on my view that filters based on the value of one field being equal to the name of the currently logged in user? The field is static.

2
  • Can you describe the question little bit more. What i understood you want to show a list of records/record based on user login.
    – DRUPWAY
    Feb 10, 2017 at 9:30
  • As per my assumption I believe you can achieve using contextual filter.
    – DRUPWAY
    Feb 10, 2017 at 9:36

3 Answers 3

2

You can use contextual filter, as suggested by DRUPWAY in his comment.

  1. Add a new contextual filter
  2. Select the field to use
  3. For When the filter value is NOT in the URL, select Provide value, and then PHP code for Type
  4. In PHP contextual filter code, enter the following code
    global $user;
    return $user->name;
    

screenshot

For the user ID, it would be simpler: In step 3, you would select User ID from logged in user.

screenshot

0
1

In view Relationships add "author" then in FILTER CRITERIA Add (User: Current) and select (yes) in "Is the logged in user"..

2
  • Hi @a.alshamiri, please try not to provide one-sentence answers. If possible provide a step-by-step guide with screenshots of each step, or of the final configuration screen. Thanks! Feb 13, 2017 at 15:29
  • But the field I want to match isn't author.
    – Sam
    Feb 13, 2017 at 16:23
0

In Drupal 8 you can just use the module:

https://www.drupal.org/project/user_field_value

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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