How to change the sorting of a view using hook_views_pre_view()?
Posted
by RD
on Stack Overflow
See other posts from Stack Overflow
or by RD
Published on 2010-04-27T08:50:51Z
Indexed on
2010/04/27
8:53 UTC
Read the original article
Hit count: 240
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?
© Stack Overflow or respective owner