How to change the sorting of a view using hook_views_pre_view()?
- by RD
I've got the following:
function view_sorter_views_pre_view(&$view) { // don't need $items
if ($view->name == 'MOST_RECENT') {
$insert = array();
$insert[order] = 'DESC'; //SORT ORDER
$insert[id] = 'title';
$insert[table] = 'node';
$insert[field] = 'title';
$insert[override] = array();
$insert[override][button] = 'Override';
$insert[relationship] = 'none';
unset ($view->display['default']->display_options['sorts']['title']);
$view->display['default']->display_options['sorts']['title'] = $insert;
}
}
Basically, I'm just changing the sort order... but this does not appear on the view when opening it. Any idea why?