We use cookies to improve your experience. No personal information is gathered and we don't serve ads. Cookies Policy.

ExpressionEngine Logo ExpressionEngine
Features Pricing Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University
Log In or Sign Up
Log In Sign Up
ExpressionEngine Logo
Features Pro new Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University Blog
  • Home
  • Forums

Sort Channel Entries by a Number

How Do I?

futuristonline's avatar
futuristonline
43 posts
10 years ago
futuristonline's avatar futuristonline

Hi Everyone I have a site where i am trying to sort the entries of a channel by a number. I have two custom fields, one for name and the other for score. The score can be anything from 100 to 0. However, when I order this custom field by the score, it puts everything in order (sort=”desc|asc”) but it places the 100 scores at the bottom.

eg

Name - 99 Name - 90 Name - 74 Name - 100

I assume this is something to do with the fact that EE is sorted based on the first digit, so its thinking its starts with a 1 instead of recognising it by the number of digits, etc.

Does anyone know anyway round this?

Thanks

Steve

       
sheferd's avatar
sheferd
31 posts
10 years ago
sheferd's avatar sheferd

This should be possible but you need to make sure the data type (‘Field Content’) is set correctly. Inside the field set up if you select ‘Text Input’ as field type you’ll then have an option at the bottom of the field set up page called ‘Field Content’. Here you have ‘All’, ‘Number’, ‘Integer’ and ‘Decimal’. If you are going to be working with Whole numbers then select ‘Number’.

If your field is set to ‘All’ then it will be treated as alphabetical I.E. 1 comes before (or after, depending on sort order) 9 so you end up with 1,11,100,2,24,9,99 etc, Number should treat them properly as numbers so you’ll have 1,2,9,11,24,99,100.

Hope this helps

       
futuristonline's avatar
futuristonline
43 posts
10 years ago
futuristonline's avatar futuristonline

Brilliant - thanks for that - fixed!!!

       

Reply

Sign In To Reply

ExpressionEngine Home Features Pro Contact Version Support
Learn Docs University Forums
Resources Support Add-Ons Partners Blog
Privacy Terms Trademark Use License

Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.