Score:0

Views Exposed filter can't input username to filter. Only works with User ID

kr flag

I created a custom View, where it shows all of a specific content type. In this content type I have a field that is a user reference called "Assigned to". In this view, I want it exposed so one can search by a username, but this exposed filter only takes in the User ID, but not the user name. What am I missing to make this work?

I added a relationship of User:Assigned_To and that didn't seem to work or I'm not configuring it properly.

enter image description here

Score:2
in flag

Looks like you're filtering by the actual entity reference field field_assigned, which will naturally just take the user ID because the field itself only knows only about the ID of the referenced entity (specifically, it stores the user ID in the target_id)

In order for you to filter against usernames, you:

  1. Add a filter to the username field.
    • When choosing the field the filter, narrow the category down to User. That way you can find and select the username field.
  2. When configuring the filter, set the relationship to the one that connects your content type to the user via the field_assigned field.
    • This is needed because you can have another entity reference field that also points to User (e.g. something like a "reviewed by"), and Views needs to know which field you meant to use.

Added bonus: Enable SQL debugging in Views settings. That way you can see the resulting SQL query done by Drupal. This will tell you if you're filtering against the right columns or missing some joins.

I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.