1

So, I have a view of a content type, and this content type has three unique taxonomy terms it are: Alpha, Beta, and Both.

Currently, my view lists all nodes of this type, and I've added an exposed filter that lets the user select one and only one of the three terms above, like so:

Both -> Show only content tagged Both

Alpha -> Show only content tagged Alpha

Beta -> Show only content tagged Beta

What I would now like to do is extend the behaviour of the filter so that the following happens:

Both -> Show only content tagged Both

Alpha -> Show only content tagged Alpha and Both

Beta -> Show only content tagged Beta and Both

So as you can probably see, if something is Both, then it is also Alpha and Beta. Obviously the taxonomy terms themselves don't contain this semantic information.

I cannot use "All" to represent Both because then selecting Both -> Alpha, Beta, Both.

So I'm thinking that somehow I could make Alpha and Beta a child term of Both, and Better Exposed Filters might allow this logic to work? Or will I need to use a hook - if so, which hook and any ideas about how I might approach it?

6
+50

You need to use hook_views_query_alter(). And the logic would be as below.,

  1. Both -> Show only content tagged Both

    When the user selects the Both, make no changes in the hook, just return the default result. So by this way the contents tagged under Both will be displayed.

  2. Alpha -> Show only content tagged Alpha and Both

    Now use the alter hook, by default the query will have alpha's tid in it. Here you need to add the Both's tid to the query. So now the Alpha and the Both will be displayed.

  3. Beta -> Show only content tagged Beta and Both

    Now use the alter hook, by default the query will have Beta's tid in it. Here you need to add the Both's tid to the query. So now the Beta and the Both will be displayed.

In simple term, just use the alter query and add the Both's tid to it. So that we will get the Both's content in all cases.

  • 1
    I think the exposed filters uses GET method to filter the result. If that is the case, why cannot we simply append the tid to the GET instead of the hook? Drupal way of doing ?? – user4081 Oct 28 '13 at 12:43
  • "And the login would be as below" what is that ???? logic or login ? – Bala Oct 28 '13 at 13:05
  • It was logic, I corrected it now ! – Gladiator Oct 28 '13 at 13:06
1

The Views PHP module could let you write your own logic for when the taxonomy term matches.

0

This is a great case for using grouped exposed filters! I don't have a D6 site handy to see if they are supported in views 6.x-3.x, but I'm fairly certain that they are available in D6.

Heres a screenshot example of how I've configured an exposed views grouped filter similarly to how you are describing.

enter image description here

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.