4

I have a view with an exposed "sort by" form.

I don't know how to skip this sort if the user did not chose any sort mode.

My view has this exposed sort widget and the second sort criteria (not exposed) is by node sticky property. The problem is the view sorts the content by the first criteria, even though the user didn't chose something.

How can I change that? Thanks

  • I know how to do that for Table style plugin. Table display allows overriding normal sorting if click sorting is used. – kalabro Aug 21 '12 at 19:08
2

I just had this problem (well, similar) and I solved it the following way:

/**
 * Implements hook_views_pre_build().
 */
function MY_MODULE_views_pre_build(&$view) {
  // Trigger this only for the needed view
  if ($view->name == 'my_view_name') {
    // Check the exposed input array to see what the user submitted
    $exposed_input_arr = $view->get_exposed_input();
    // Write your exposed array checking logic here ...
    //if (empty($exposed_input_arr['field_sort_by']) || ...) {
      // Remove the sort field from the view
      unset($view->sort['field_sort_by']);
    //}
  }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.