By drupalninja99 on
I've posted this question here: http://drupal.org/node/258188 and haven't gotten a response. I'd rather pay a fast ransom ($50?) for a quick fix what I'd need to sort CCK fields. Here is the example:
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;
I am sure ppl have done this, you see the last clause in this if statement is a CCK field but this code will break. I need to know how to fill out the params "tablename", etc.
I'm looking for someone who's already done this and can give me a quick fix for a quick ransom and then I can move on bc I don't want to have to spend a lot of time trying to research this. Please message me if interested, thanks!
Jay
Comments
Here is the way I would
Here is the way I would solve this. I would start with the view you have and under sort criteria add a sort by 'price' criteria. Now export the view and look at the generated sort (repeat as needed for other sort criteria)
This is what I'm trying now
And it's still not working. I copied exactly what the view was doing when I set the sort field in the edit view page. All I did was set it by the query string and yet it's not working? The listings show up fine they just don't sort no matter what I do. Help!
Where does this code exist
Where does this code exist (what is the context)? And the use of $_GET['sort'] suggests you have a form method set to GET while drupal forms use method=POST by default so how are you producing the form?
Well...
I'm going to make a dropdown or something that will populate the query string. That's not the issue. The crazy view sorting that is so difficult is my problem =)
This will be solve the problem
pls try this, hope it work :
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'] = 'node_data_field_price.field_price';
$view->sort[0]['sortorder'] = $_GET['order'];
$view->sort[0]['options'] = 0;
$view->sort[0]['tablename'] = 'node_data_field_price';
$view->sort[0]['id'] = 'node_data_field_price.field_price';
}
return $args;
Best Regards,
Dhara
YM, MSN, Skype : dhara_ok
Paypal : dhara_ok@yahoo.com
www.bengkel.web.id - total web solution
Still get an error
It's not tried to join the CCK table, driving me nuts!
This is the export of my view
I'm guessing I can't do what I want to do through the arguments
I've tried the last day or so to create a php page and call the view, override the sort logic then display the view and that doesn't work either.
I think I finally got it
I swear I did this yesterday and yet yesterday it wasn't working. It must have been just subtlety different. Anyways all I do is call the view and then override the sort. I added the 3 fields I'm sorting to the sort box in the edit view screen. Then I did a print_r on the $view object to see what it was generating. I grabbed that and then made it configurable by the query string and threw all that in a php page. I ran some tests and finally it looks like it's working. I tried all 3 fields and asc and desc order. I guess I will just make this a page and drop a javascript dropdown that will let you sort by maybe 4-5 different fields and be done with it. Hallelujah!
Use arg(x)
I realize that you are embedding the view. But can't you just put this in the argument handling and use arg(n)?