I have a view that show all contents of type NEWS NEWS has like fields :
Content = Title
Scheduler = publish-on
and in sort criteria : I want sort contents with two option : With scheduler (publish-on = DESC) and With post date
I want sort content with scheduler, and when scheduler field is empty he sort with post date. I have created hook views query alter and I have a problem, how can I sort field with condition if publish_on is empty then sort with postdate
function custom_sort_views_query_alter(&$view, &$query) {
if($view->name === 'articleview') {
$view->query->add_where(1,'publish_on', 'NOT IN');
$view->query->orderby[0]['field'] = "CASE WHEN publish_on IS NULL THEN created ELSE publish_on END";
$view->query->orderby[0]['direction'] = "DESC";
$view->query->orderby[1]['field'] = "created";
$view->query->orderby[1]['direction'] = "DESC";
}
}