Extending Views 2 to expose sorting options


/ Published in: PHP
Save to your folder(s)



Copy this code and paste it in your HTML
  1. function expose_order_by_views_query_alter(&$view, &$query)
  2. {
  3. if( isset( $_GET['sortoptions'] ) )
  4. {
  5. $_SESSION['sortoptions'] = $_GET['sortoptions'];
  6. }
  7. if ( $_SESSION['sortoptions'] == 'A-Z' )
  8. $query->orderby[0] = 'node_title ASC';
  9. else if ( $_SESSION['sortoptions'] == 'Z-A' )
  10. $query->orderby[0] = 'node_title DESC';
  11. else //No Session Data
  12. {
  13. $_SESSION['sortoptions'] = 'A-Z';
  14. $query->orderby[0] = 'node_title ASC';
  15. }
  16. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.