5

With Views 2.x, Drupal 6, I've created a taxonomy and have enabled it for a Content Type. I then create some content:

node_1 is associated with term_1 (tid=1)
node_2 is associated with term_2 (tid=2)
node_3 has no term association

I've created a Node View that has an Argument for "Taxonomy: Term ID". In the argument configuration, I enable "Allow multiple terms per argument".

Using the Live Preview for the View, I can pass in arguments. So I pass in "1" and the view shows me node_1. I pass in "2" and the view shows me node_2. I pass in "1+2" and the view shows me node_1 and node_2. This is good.

What I can't figure out is how to pass an argument that will return me just node_3. Is there something I can pass to Arguments that essentially means "no argument"?

1

Just in case anyone else stumbles upon this answer, we solved this problem with the following approach:

function MODULENAME_views_query_alter(&$view, &$query) {

  if($view->name == 'your_view_name')){

    //Flip the term table join to a LEFT join
    $view->query->table_queue['term_node_value_0']['join']->type = 'LEFT';

    //CLear the extra condition (removes a where clause on the join limiting only matching term ids)
    $view->query->table_queue['term_node_value_0']['join']->extra = null;

    //Look through the where clauses and add a null condition clause
    if($index = array_search('term_node_value_0.tid = %d', $query->where[0]['clauses'])){
      $query->where[0]['clauses'][$index] .= ' OR term_node_value_0.tid IS NULL';
    }
  }
}

It changes the JOIN type to a LEFT join, removes the limiting clause from that join and adds a condition to match against null values. It's obvious limitation is that it should be using aliases instead of hard coding the field name.

The function should go in your modules views.inc file where Views expects to find this hook.

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.