Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
Pages: 1
Sort using custom field
I have what should be a simple issue. I’m doing a real estate site, using a custom field to enter the property price. On the listings page the customer wants the properties listed from low to high. Simple enough.
Here is the code in the page:
<txp:article_custom listform=“listing_list” category=“homes” limit=“20” sort=“custom_1 asc” />
Here is the problem. It sorts fine for prices entered up to 999,000. But a property valued over 1,000,000 is listed BEFORE the properties under 1,000,000. It is as if Textpattern cannot see the 7th digit in the number. I’ve tried both with and without commas – no difference.
Ideas?
Offline
Re: Sort using custom field
It’s sorting alphabetically. Try sort="custom_1 + 0"
to force a numeric sort.
Code is topiary
Offline
Re: Sort using custom field
Tried that – no apparent change.
It is sorting all the under 1,000,000 properties correctly – that is why I’m wondering if it can’t see the 7th digit.
Offline
Re: Sort using custom field
towndock wrote:
It is sorting all the under 1,000,000 properties correctly – that is why I’m wondering if it can’t see the 7th digit.
As Jeff said it’s sorting alphabetically (compares as strings), not numerically. It is seeing the 7th digit, it just sorts like strings should.
Currently it should be sorting in following pattern:
1
10
100
1,00
2
8000
9
If the +0
didn’t work, you could try to remove the grouping commas which MySQL might be reading as decimal pointers.
If it doesn’t work even then, you could try to change the custom_1 field’s type to suitable numeric, possibly decimal(12,2)
or int(11)
. The field can be found from textpattern table. You can do the change with a DB manager like phpMyAdmin or by directly running commands.
Last edited by Gocom (2010-08-26 17:37:26)
Offline
#5 2010-08-26 17:32:59
- els
- Moderator
- From: The Netherlands
- Registered: 2004-06-06
- Posts: 7,458
Re: Sort using custom field
jsoo wrote:
Try
sort="custom_1 + 0"
to force a numeric sort.
towndock wrote:
Tried that – no apparent change.
Are you entering the values with the commas (999,000 and 1,000,000)? I think Jeff’s method will only work if you enter them without seperators (999000 and 1000000).
Edit: while I was typing Jukka added exactly this to his post ;)
Last edited by els (2010-08-26 17:34:05)
Offline
Offline
Re: Sort using custom field
You’re correct – adding the “+ 0” to the sort command AND removing the commas make it work.
Thank you much to the TXP community.
Offline
Pages: 1