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?
I believe what you want is
Views uses the handler object to build the query instead of the display_options. The display_options contain all the options for every display type that the view contains (eg. default, page_1, block_1, etc…). The ‘handler’ object holds the options that will be used to actually build the current display.
Note: I simplified the code to only change the sort order. The rest of your code should work, just change the last two lines to