I'm trying to filter my view based on data in a single field. My field targetuser contains a string of numbers: 47,505,100,20.

I'm trying to setup the view so that if targetuser contains the logged in user ID (in this case, that's 47), the content should be visible.

The view's setup

However, the setup I have now only works if a single number is inside that field, not four numbers.

How can I accomplish this?

Note, I've installed the Views Argument Substitution module. The settings for the second contextual filter I'm referencing are the following.

content:targetuser:provide default value: logged in user id


Update: For those wondering, the existing Contextual Filters so far do the following:

Show node if:

  • Content: Author uid (logged in user is also the author of the node)
  • Content:targetuser (if target user is equal to logged in uid)OR IF
  • Content:targetuser (if target user field is equal to 9506)
  • What type of a field is the Target user field? text, integer, entity reference? It doesn't seem that Views Argument Substitution can help you in your case, it filters results, not validation criteria, and you seem to want to hide the views depending on this filter. You might need some custom code to extract the comma-separated values from a text field if that's your case. Why do you have 3 contextual filters? They all need to be satisfied at the same time and it's very difficult to construct something that works. You can follow that module instructions to filter out the views results. – prkos Mar 20 at 18:43
  • @prkos target user field is a textfield. Would this work if it were an integer field? – Brittany Mar 20 at 20:29
  • If you're considering changing your structure I think it makes the most sense to have it Entity reference field that actually references users. – prkos Mar 20 at 20:46
  • Just realized I'm unable to change my structure... the text field already holds existing data :/ @prkos That said, my contextual filter that uses targetuser = logged in user id works perfectly...so I'm not sure why comma separated values would be an issue? Any other tricks I could try? – Brittany Mar 20 at 20:50
  • Please update the question with that information, how does targetuser field work? If it works what are you actually asking? Text field is a text field, it's not numbers separated by commas, it's all just text characters. You'd have to do some custom code to parse that text as if it were comma separated numbers and pass that to the contextual filter, then it could work. – prkos Mar 20 at 22:06

Your Answer

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

Browse other questions tagged or ask your own question.