I grabbed some code from book pages and put it in my view argument handling code box. I'm trying to add a sort for the custom CCK field "field_price". I tried this but failed, I don't know how to make the view join that table. I don't really know what I'm doing. Can anyone help?

if ($_GET['sort']== "title") {
  $view->sort[0]['position'] = 0;
  $view->sort[0]['field'] = 'node.title';
  $view->sort[0]['sortorder'] = $_GET['order'];
  $view->sort[0]['options'] = '';
  $view->sort[0]['tablename'] = '';
  $view->sort[0]['id'] = 'node.title';
}
else if ($_GET['sort']== "date") {
  $view->sort[0]['position'] = 0;
  $view->sort[0]['field'] = 'node.created';
  $view->sort[0]['sortorder'] = $_GET['order'];
  $view->sort[0]['options'] = '';
  $view->sort[0]['tablename'] = '';
  $view->sort[0]['id'] = 'node.created';
}
else if ($_GET['sort']== "price") {
  $view->sort[0]['position'] = 0;
  $view->sort[0]['field'] = 'field_price';
  $view->sort[0]['sortorder'] = $_GET['order'];
  $view->sort[0]['options'] = '';
  $view->sort[0]['tablename'] = '';
  $view->sort[0]['id'] = 'field_price';
}
return $args;

Comments

drupalninja99’s picture

Seems like it should be pretty easy to do, but I can't figure it out. I just need learn how to sort by CCK fields when using views.

drupalninja99’s picture

I know somebody has to know, right? Please help!

kulfi’s picture

I'm trying to do the same with no joy. Did you ever get this working?

Also, do you still have the handbook page's URL?

drupalninja99’s picture

in another thread i figured it out, search my posts and you should find it -J

laken’s picture

I was unable to find the solution searching your other threads. It would be great if you'd take a moment to update this thread with the answer so that people who fins this page through search (like I did) won't be frustrated.

Many thanks!

drupalninja99’s picture

http://drupal.org/node/265857

Sorry, hope this helps =)

laken’s picture

Thanks for updating!