I’ve added a custom field to a view and want to display results as a grid grouped by this field. How do I set that “Grouping field Nr.1” option in my code? I tried the following but it doesn’t work (probably I’m doing it in the wrong place or change wrong setting…)
function MYMODULE_views_query_alter(&$view, &$query)
{
$view_name = 'MYVIEW';
$display_name = 'MYDISPLAY';
if ($view->name == $view_name && $view->current_display == $display_name)
{
$custom_field = 'field_MYFIELD_value';
//code piece adding this field to a view's SELECT statement, sorting by it etc
$style_options = $view->display['default']->handler->options['style_options'];
$style_options['grouping'][0]['field'] = $custom_field;
}
}
Sponsored by SupremePR