Drupal: Access A Field in hook_views_query_alter()

1k views Asked by At

I have content type picture which has a field with the machine name score. I have implemented the hook_views_query_alter() which looks like the following; the main part is that I add a line which adds an extra where condition:

function pic_anlysis_views_query_alter(&$view, &$query) 
{
    ...
    $query->where[1]['conditions'][2] = array('field'=>"node.score","value"=>array(30, 60),"operator"=>"BETWEEN");
}

But the above doesn't work; I think that node.score is the wrong key used to represent the field in the query. Anyone knows what I should use instead?

Thanks

1

There are 1 answers

1
wikp On

Fields are not stored in node table.

Try

$query->add_where(1, 'field_data_field_score.value', array(30, 60), 'BETWEEN');