I'm trying to use hook_views_query_alter()
to select some nodes based on a calculation using two fields in that node. I can't find much documentation or many examples that help me understand how this works.
I could use Views PHP, but this module is very buggy in Drupal 7.
I think I need to use $query->add_where_expression() but I can't work out how to use it.
My view is called "latlong", and as a test to see if I have the right approach, I've tried to select nodes based on the value of field_latitude. Copying other functions i've seen through googling, this is my best guess, but it's not working. I know one of my nodes has the value 53.9519 so if my syntax is right I should get a row back, but I don't:
function my_module_views_query_alter(&$view, &$query) {
switch($view->name) {
case 'latlong':
$query->add_where_expression(0,'field_data_field_latitude.field_latitude_value = 53.9519');
break;
}
}
If I print_r($query->where[0])
I get:
Array (
[conditions] =>
Array (
[0] =>
Array (
[field] => field_data_field_latitude.field_latitude_value = 53.9519
[value] => Array ( )
[operator] => formula ) )
[args] => Array ( )
[type] => AND )
What am I doing wrong?