Jump to content

Sorting using parent's pagefield


alxndre
 Share

Recommended Posts

I'm trying to sort pages based on their parent's fields, which are page references.

For instance:

$someOrders = $pages->find("template=order, sort=parent.customer.id");

Here, order's parent has a template called 'orderslip' that has multiple 'order' children. Orderslip contains a page field called customer, and I want to sort based on the parent's customer's id. But i can't make it work. It throws out an exception:

Error: Exception: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'customer' in 'order clause' (in /srv/rewwwards/wire/core/PageFinder.php line 410)

I'm sure customer page field exists and it works everywhere else. It's just that this time, I'm trying to sort it from a page's 'parent' selector. Is it even possible do this?

As always, any help is greatly appreciated. :) Thanks.

Link to comment
Share on other sites

2 minutes ago, Zeka said:

Hi @Alxndre'

Not sure, but looks like you should use sub-selectors in this case 

https://processwire.com/api/selectors/#sub-selectors

Hi, @Zeka,

Sorry for the big edit, I was totally swimming in my head coding til morning. But thanks for pointing me to subselectors! I've been using ProcessWire since 2012, but never heard of it and it looks amazing. I should probably read the PW weekly more often. :)

  • Like 1
Link to comment
Share on other sites

1 hour ago, Alxndre' said:

Searching using subfields values is working fine, for some reason, I can't make sorting with parent.pagefield work.

I can confirm. Seems like a bug to me - I tried sorting on a range of different fieldtypes in the parent page and they all worked apart from a Page Reference field, which gives the error shown in the first post.

@Alxndre', I suggest you create a GitHub issue for this so Ryan can take a look.

  • Like 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
 Share

×
×
  • Create New...