Jump to content

Get template sorted by dropdown field [SOLVED]


Recommended Posts


First, this is production realestate site, big one. So please, if any chanse to fix this without touching database, it would be great

I have field "pstatus" as a PageReference,

In the tree under Status as children:

  • sold
  • unavailable
  • paused

In the template "property" I have dropdown were I choose: empty (nothing); sold; unavailable or paused. If you do not choose anything, property will have active selling status.

I need help sorting property template in this order: show all empty and than show all sold.

1031 is Status, parent of the sold unavailable and paused.

    $status = $pages->get('1031')->children('sort=pstatus');

    $selector[] = "sort=price, pstatus!=$status";

But I got there all except from status. I need to list "sold" too.


Link to comment
Share on other sites

Your selector would go something like:

$properties = $pages->find("template=property, pstatus=''|sold, sort=pstatus, sort=price");

This works because when you sort by the value of pstatus an empty value will sort before any other value. Which is fine in this case because you happen to want the pages with empty pstatus (available properties) to sort first.

But you actually get more complete control of sort order if you create a status page for "available", make the pstatus field required, and set the default value of pstatus to "available". That way you can set the sort position of the "available" page to some other position than first if you happen to need to change to that at some time in the future. Then in your selector you can sort by the sort value of the status page selected in the pstatus field. So if you needed to find properties with statuses "available", "sold" and "paused" and the sort order of those status pages in the tree is "paused", "available", "sold" then your results would get that same sort order with this selector:

$properties = $pages->find("template=property, pstatus=available|sold|paused, sort=pstatus.sort");


  • Like 1
  • Thanks 1
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...