Jump to content

$page->children("sort.... from smallest to greatest number


Recommended Posts


I have encountered the following problem in the otherwise magnificent CMS ProcessWire:

I'm sorting pages according to: "$page->children("sort=...". This is principally working fine, but the problem occurs when values like the following are returned: "10,4m3; 10m3; 8m3...". ProcessWire interprets them as text, which means that it thinks that e.g. "8m3" is greater than "10m3" seeing how the earlier begins on a greater number.

Does anyone have any ideas how I could work around this issue, and indeed get PW to sort the values in the following order: "8m3; 10m3; 10,5m3...".


Link to comment
Share on other sites

I don't think you'll be able to do that in a PW selector, but you can sort it after you have the page array.

I asked this question a long time ago - that thread should help you:


I am not sure if natsort works with comma decimals, but maybe there is an alternative php function you can use if needed? 

I am sure one of the european PW devs will have some input if this is an issue.

PS Welcome to the forums!

  • Like 1
Link to comment
Share on other sites

Hi Matte85,

Welcome to PW and the forums...

Technically, this is a PHP issue and not a PW one :-). What you are looking for is PHP's  natsort — Sort an array using a "natural order" algorithm or the related natcasesort — Sort an array using a case insensitive "natural order" algorithm. The implementation of the former can be seen in the following posts:





A shortcoming is that you probably want to grab a limited number of children based on the natural sort, rather than sorting after grabbing them...Not sure how to overcome this.


I am late to the party as usual! Beaten by @Adrian :-)

Edited by kongondo
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Create New...