- First commit to issue fork.
Updated: Comment #3 by dooug
I am trying to sort nodes by the combination of two different date fields. The View can be sorted by one date field, but using two date fields in the sort will sort by one field first, then the other.
I want to achieve this: (Nodes are being sorted by date, no matter if the date is from "date-field 1" or "date-field 2")
By setting up views "sort" panel adding the two date fields will render the following view:
It sorts the date field correctly, but wont combine the date-fields. So the Dates are getting mixed up completely.
There appear to be a handful of requests for this, including but not limited to:
#378694: sort by date, combining fields →
http://stackoverflow.com/questions/12578343/drupal-views-multiple-sort-c...
http://stackoverflow.com/questions/11769902/drupal-7-sorting-multiple-co...
http://drupal.stackexchange.com/questions/32679/how-do-i-sort-two-differ...
Summary of possible solutions / work-arounds:
(likely) Best solution (at the time of writing this):
In a custom module use the hook_views_query_alter() function to alter the sort criteria to use CASE ... WHEN
to add a conditional in the orderby condition. A good example is shown here:
/**
* Implements hook_views_query_alter
* @param type $view
* @param type $query
*/
function MODULE_views_query_alter(&$view, &$query) {
if ($view->name == 'views_name' && $view->current_display == 'display_name') {
$query->orderby = array(
array(
'field' => 'CASE WHEN field_data_field_date_publication.field_date_publication_value THEN field_data_field_date_publication.field_date_publication_value ELSE node.created END',
'direction' => 'DESC',
)
);
}
}
Credit goes to eloone here: https://drupal.org/comment/6443200#comment-6443200
Closed: won't fix
3.0
Code
Not all content is available!
It's likely this issue predates Contrib.social: some issue and comment data are missing.