Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2010-07-24 04:46:37

smdnetau
Member
From: Sydney
Registered: 2008-10-09
Posts: 52
Website

ordering by custom field

Hi,

I’m going mad (again) not being able to reverse sort some articles by a custom field:

Page template:

<txp:article_custom sort="custom_2 desc" form="product" section="collections" />

Form:

<p><txp:custom_field name="collection" /> - <txp:custom_field name="prod_name" /></p>

I’m using the field custom_2 to just take a numeral eg 1 or 10 or 20, whatever.

I can use rand(), Posted, ID, etc as the sort parameter as listed here just not “desc”.

Thanks in advance for any help.

Marty

Offline

#2 2010-07-24 08:08:50

aslsw66
Member
From: Canberra, Australia
Registered: 2004-08-04
Posts: 342
Website

Re: ordering by custom field

My understanding is that custom fields are plain text, which means that sorting by number or date doesn’t work as intended ie. 10 comes before 2. I was storing dates in a custom field and came unstuck through this lack of sorting capability.

Offline

#3 2010-07-24 08:10:29

els
Moderator
From: The Netherlands
Registered: 2004-06-06
Posts: 7,458

Re: ordering by custom field

You can use sort="custom_2 + 0 desc".

Offline

#4 2010-07-24 09:25:20

smdnetau
Member
From: Sydney
Registered: 2008-10-09
Posts: 52
Website

Re: ordering by custom field

Thanks for the replies.

sort="custom_2 + 0 desc"

… didn’t have any effect.

Offline

#5 2010-07-24 10:20:01

els
Moderator
From: The Netherlands
Registered: 2004-06-06
Posts: 7,458

Re: ordering by custom field

It should. What is the exact article_custom tag you have now?

Offline

#6 2010-07-24 10:29:49

smdnetau
Member
From: Sydney
Registered: 2008-10-09
Posts: 52
Website

Re: ordering by custom field

Hi Els,

This is the page in question:

http://schon.clientsite.net.au/collections/

Page code:

<txp:article_custom sort="custom_2 + 0 desc" limit="9999" form="product" section="collections" status="4" />

Form code:

<li>
<txp:custom_field name='collection_order' />
	<a href="<txp:permlink />"><img src='/phpscripts/phpThumb.php?src=<txp:upm_article_image type='image'><txp:upm_img_full_url /></txp:upm_article_image>&w=178zc=1&fltr[]=ric|6|6' title='<txp:custom_field name='prod_name' />' alt='<txp:custom_field name='prod_name' />' />
	<span class="prod_id"><txp:custom_field name="prod_id" /></span>
	<span class="prod_name"><txp:custom_field name="prod_name" /></span>
	<span class="prod_price">$<txp:custom_field name="prod_price" /><txp:if_custom_field name="sold_out" val="yes"><span class="sold_out">sold out</span></txp:if_custom_field></span></a>
</li>

The ugly (temporary) numbers are output by:

<txp:custom_field name='collection_order' />

I probably forgot to mention that I’m also using glz_custom_fields. The field I’m using for the ordering is set to custom_2.

-Martin

Offline

#7 2010-07-24 10:33:00

els
Moderator
From: The Netherlands
Registered: 2004-06-06
Posts: 7,458

Re: ordering by custom field

I don’t know why it wouldn’t work, or it must be the single quotes here:

<txp:custom_field name='collection_order' />

That should be double quotes.

Offline

#8 2010-07-24 10:41:44

smdnetau
Member
From: Sydney
Registered: 2008-10-09
Posts: 52
Website

Re: ordering by custom field

I’ve changed that to no effect. I’m totally stumped.

My plugins list if it helps: http://cl.ly/1l0O

Offline

#9 2010-07-24 11:06:40

smdnetau
Member
From: Sydney
Registered: 2008-10-09
Posts: 52
Website

Re: ordering by custom field

This is boring but I think I’ll just change the date on each entry and sort by Posted.

Offline

#10 2010-07-24 11:36:51

alanfluff
Member
From: Ottawa, Canada
Registered: 2008-09-15
Posts: 222
Website

Re: ordering by custom field

Hi Marty,

I think I’ve seen that effect, where sorting is ignored, but I can’t recall anything from then of help. But I can confirm that I wanted to add some arbitrary sort and to do it I just added a new glz_custom_fields custom field, I have so many it was custom_36 and ensured it was listed first in the sort= list — I didn’t even have the + 0 which I assume forces the sort to regard the parameter as numerical (cool).

My suggestion is that the form that you output be stripped of everything but say <txp:title /> tag and maybe output the value of the custom field for each article too.

If you strip back to the point where the sort is working (as it is for me in tons of places), then add back complexity, hopefully you will find it quickly.

Sorry nothing more specific to say that could help. Good luck, cheers, -Alan


At LAST I’ve cheerfully donated to the core devs at #TXP. I only wish I were able to give more. Thanks to the devs and ALL fellow TXPers. -A

Offline

#11 2010-07-24 11:45:47

smdnetau
Member
From: Sydney
Registered: 2008-10-09
Posts: 52
Website

Re: ordering by custom field

Thanks Alan.

That had actually been my approach a while ago but it came to no avail. I went to the trouble of moving the custom field up the order just to see if it made a difference but it didn’t. I’ve gone with the Posted sort for the time being.

Regards
Martin

Offline

#12 2010-07-24 11:49:27

alanfluff
Member
From: Ottawa, Canada
Registered: 2008-09-15
Posts: 222
Website

Re: ordering by custom field

Welcome.

Sorry it’s not solved.

If you (or I) find the cause, it’d be good to write it up here so if it happens again one can come back here for a quick fix.

Cheers, -Alan


At LAST I’ve cheerfully donated to the core devs at #TXP. I only wish I were able to give more. Thanks to the devs and ALL fellow TXPers. -A

Offline

Board footer

Powered by FluxBB