Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
Pages: 1
#1 2011-02-25 07:20:18
- dandul
- Member
- From: Brisbane, Australia
- Registered: 2010-01-31
- Posts: 33
sorting by custom field
Hi, I’m trying to sort a group of articles by a custom field sort="custom_4"
(which is for “day_time_code”) into ascending numerical order, so it looks like this:
day_time_code is 02
day_time_code is 03
day_time_code is 04
day_time_code is 05
When I use this code:
<txp:article_custom section="class-list" class_type="SM" sort="custom_4 desc" form="378_SMpage" />
textpattern generates what I’d expect, highest number to lowest:
day_time_code is 05
day_time_code is 04
day_time_code is 03
day_time_code is 02
but when I change sort="custom_4 desc"
to sort="custom_4 asc"
I get this:
day_time_code is 04
day_time_code is 03
day_time_code is 02
day_time_code is 05
Which isn’t what I expected!
FYI changing to sort="custom_4"
produces this:
day_time_code is 04
day_time_code is 03
day_time_code is 02
day_time_code is 05
and taking out the “sort” altogether <txp:article_custom section="class-list" class_type="SM" form="378_SMpage" />
produces this:
day_time_code is 05
day_time_code is 02
day_time_code is 03
day_time_code is 04
Apologies if I’m missing something obvious, but I’ve googled and forumed and I can’t figure it out. How does one get an ascending numerical order sort on a custom field?
Stop wishing things were different to the way they are. Accept it, deal with it, move on.
Offline
#2 2011-02-25 12:20:45
- uli
- Moderator
- From: Cologne
- Registered: 2006-08-15
- Posts: 4,315
Re: sorting by custom field
If day_time_code is 04
is a litteral example, then I’m at loss. If not, please post exact examples for what you’re trying to sort.
In bad weather I never leave home without wet_plugout, smd_where_used and adi_form_links
Offline
Re: sorting by custom field
The results you’re getting with custom_4 asc
(and just custom_4
, which is the same thing, because asc
is the MySQL default) happen to be the reverse of what you’re getting with no sort
specified, i.e. Posted desc
(the Txp default for articles). I don’t know why you’re getting this, but it is suggestive.
Code is topiary
Offline
#4 2011-02-25 17:48:45
- els
- Moderator
- From: The Netherlands
- Registered: 2004-06-06
- Posts: 7,458
Re: sorting by custom field
Check if there are any spaces in the custom field entries, in particular before the actual content.
Offline
#5 2011-02-26 02:19:56
- dandul
- Member
- From: Brisbane, Australia
- Registered: 2010-01-31
- Posts: 33
Re: sorting by custom field
Thanks for the help everyone, gave me some new things to look at. After a lot of looking I still couldn’t make it work, so I have abandoned the custom_field sort. I suspect it was actually sorting it according to some other value but I couldn’t figure out what that might be. Am now sorting the articles using the “expires” field.
Cheers!
Stop wishing things were different to the way they are. Accept it, deal with it, move on.
Offline
Pages: 1