Cengiz Deniz Posted May 10, 2017 Share Posted May 10, 2017 I use pagination modul. I have a field which has born year info. But I put the years with sign "-" for BC (Before Christ). my selector sorts like as text. -384, -4, -412 .. it must be: -412, -384, -4 selector: $pages=$page->children("limit=60, sort=date_field"); I want to order my pages like as php natsort function. thank you. Link to comment Share on other sites More sharing options...
Robin S Posted May 11, 2017 Share Posted May 11, 2017 Is there a reason why your year field is a text field and not an integer field? If you use an integer field it will sort as you want it to. 2 Link to comment Share on other sites More sharing options...
LostKobrakai Posted May 12, 2017 Share Posted May 12, 2017 On 10.5.2017 at 11:07 PM, Cengiz Deniz said: I want to order my pages like as php natsort function. Without changing the fieldtype your only option is customizing the mysql query generated by processwire manually. 1 Link to comment Share on other sites More sharing options...
Cengiz Deniz Posted May 12, 2017 Author Share Posted May 12, 2017 2 minutes ago, LostKobrakai said: Without changing the fieldtype your only option is customizing the mysql query generated by processwire manually. i think this is answer. but i dont know how can i do ? 21 hours ago, Robin S said: Is there a reason why your year field is a text field and not an integer field? If you use an integer field it will sort as you want it to. is it possible changing field type to integer in PW ? Link to comment Share on other sites More sharing options...
Robin S Posted May 12, 2017 Share Posted May 12, 2017 1 hour ago, Cengiz Deniz said: is it possible changing field type to integer in PW ? You cannot directly change a text field to an integer field, but you can... 1. Create a new integer field 2. Add the integer field to the template that has your text field 3. Copy the value of the text field to the integer field using the API: $items = $pages->find("template=my_template"); foreach($items as $item) { $item->of(false); $item->my_integer_field = $item->my_text_field; $item->save(); } 4. Check that the values have been copied successfully, and if so remove the text field from your template and then delete the text field. 3 Link to comment Share on other sites More sharing options...
Cengiz Deniz Posted May 12, 2017 Author Share Posted May 12, 2017 24 minutes ago, Robin S said: You cannot directly change a text field to an integer field, but you can... 1. Create a new integer field 2. Add the integer field to the template that has your text field 3. Copy the value of the text field to the integer field using the API: $items = $pages->find("template=my_template"); foreach($items as $item) { $item->of(false); $item->my_integer_field = $item->my_text_field; $item->save(); } 4. Check that the values have been copied successfully, and if so remove the text field from your template and then delete the text field. It works now. Thank you very much. You are realy hero Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now