Skip to main content
added 238 characters in body
Source Link

I have two user roles that have term reference fields tied to profiles. One has a single select (user role A) and the other a multi select (user role B), but they reference the same taxonomy.

I have a view that lists all nodes of type AC submitted by various users with a single user reference to user role A. My goal is to filter this to those with a user reference who havehas a term reference in common with a user of role B. The view is accessed by visiting user B's profile page and displayed as a block.

My thinking was to first add a relationship to the single select taxonomy term reference for role A. Then, add a contextual filter that loads the user id from the current URL and puts all the term IDs from the multiselect into the arg, for example 3+5+9. Finally, I would do custom PHP or Taxonomy term validation to see if user role A is in this list.

Setting the argument works fine. I can dsm this and see the correct TID. For validation, custom PHP doesn't seem to work at all. No rows are returned even when I simply do a "return true;" in there. For taxonomy term, I have it set to

  • Validator: Taxonomy term
  • My vocab is checked
  • Filter value type: term id
  • Action: no results found

Any idea what I'm doing wrong or the correct way to solve this problem?

EDIT: There was a problem with htaccess which explains why return true was failing. However, I still can't quite get the contextual filter and relationship logic down.

I have two user roles that have term reference fields tied to profiles. One has a single select (user role A) and the other a multi select (user role B), but they reference the same taxonomy.

I have a view that lists all nodes of type A submitted by various users. My goal is to filter this to those who have a term reference in common with a user of role B. The view is accessed by visiting user B's profile page and displayed as a block.

My thinking was to first add a relationship to the single select taxonomy term reference for role A. Then, add a contextual filter that loads the user id from the current URL and puts all the term IDs from the multiselect into the arg, for example 3+5+9. Finally, I would do custom PHP or Taxonomy term validation to see if user role A is in this list.

Setting the argument works fine. I can dsm this and see the correct TID. For validation, custom PHP doesn't seem to work at all. No rows are returned even when I simply do a "return true;" in there. For taxonomy term, I have it set to

  • Validator: Taxonomy term
  • My vocab is checked
  • Filter value type: term id
  • Action: no results found

Any idea what I'm doing wrong or the correct way to solve this problem?

I have two user roles that have term reference fields tied to profiles. One has a single select (user role A) and the other a multi select (user role B), but they reference the same taxonomy.

I have a view that lists all nodes of type C submitted by various users with a single user reference to user role A. My goal is to filter this to those with a user reference who has a term reference in common with a user of role B. The view is accessed by visiting user B's profile page and displayed as a block.

My thinking was to first add a relationship to the single select taxonomy term reference for role A. Then, add a contextual filter that loads the user id from the current URL and puts all the term IDs from the multiselect into the arg, for example 3+5+9. Finally, I would do custom PHP or Taxonomy term validation to see if user role A is in this list.

Setting the argument works fine. I can dsm this and see the correct TID. For validation, custom PHP doesn't seem to work at all. No rows are returned even when I simply do a "return true;" in there. For taxonomy term, I have it set to

  • Validator: Taxonomy term
  • My vocab is checked
  • Filter value type: term id
  • Action: no results found

Any idea what I'm doing wrong or the correct way to solve this problem?

EDIT: There was a problem with htaccess which explains why return true was failing. However, I still can't quite get the contextual filter and relationship logic down.

Source Link

Views contextual filters for user term references

I have two user roles that have term reference fields tied to profiles. One has a single select (user role A) and the other a multi select (user role B), but they reference the same taxonomy.

I have a view that lists all nodes of type A submitted by various users. My goal is to filter this to those who have a term reference in common with a user of role B. The view is accessed by visiting user B's profile page and displayed as a block.

My thinking was to first add a relationship to the single select taxonomy term reference for role A. Then, add a contextual filter that loads the user id from the current URL and puts all the term IDs from the multiselect into the arg, for example 3+5+9. Finally, I would do custom PHP or Taxonomy term validation to see if user role A is in this list.

Setting the argument works fine. I can dsm this and see the correct TID. For validation, custom PHP doesn't seem to work at all. No rows are returned even when I simply do a "return true;" in there. For taxonomy term, I have it set to

  • Validator: Taxonomy term
  • My vocab is checked
  • Filter value type: term id
  • Action: no results found

Any idea what I'm doing wrong or the correct way to solve this problem?