Sort order issue in expressionengine 1.x

February 11th, 2011 § Leave a Comment

You might noticed the issue for sorting stuff in expressionengine cms to show entries if you’ve worked with this, that is if you’ve a custom field which stores number value and later you want sort the entries by that field – the entries sorted in wrong order! If you didn’t noticed that yet, explaining…

Let you have a custom field named “display_order”. This field stores integer value. Later you’ve tag like bellow to show entries in specific display order by this field –


{exp:weblog:entries  channel="channel_name"  orderby="display_order" sort="asc"  limit="15"}
content
{/exp:weblog:entries}

Above code pulls data in wrong order. Because Expressionengine creates varchar type field in table for every custom field. So if an entry has value 2 for display_order and 10, the entry with value 10 will comes first as mysql query treats them as string.

For this, you can do a quick trick. First find which field is created for the custom field you created, as per above example find out the field created for custom field “display_order”. Lets say table field for this custom field is field_id_20. Alter this field as integer type. So prepare a query like below and execute –

ALTER TABLE exp_weblog_data CHANGE `field_id_20` `field_id_20` INT(11) DEFAULT NULL

So, now see – issue is fixed ;)

Advertisement

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

What’s this?

You are currently reading Sort order issue in expressionengine 1.x at Codegeek.

meta

Follow

Get every new post delivered to your Inbox.