Jump to content

[SOLVED] Sort by parent field


LAPS
 Share

Recommended Posts

Hi, I find pages by using something as like the following:

$result = $pages->find("template=template_children_name, field_children_name=$page->id, parent=[field_parent_name=1]");

I would like to sort the result by a parent field, say field_parent_sort_name, to output an ordered list.

I tried the following without success:

// Attempt 1
$result = $pages->find("template=template_children_name, field_children_name=$page->id, parent=[field_parent_name=1], sort=parent.-field_parent_sort_name");

// Attempt 2
$result = $pages->find("template=template_children_name, field_children_name=$page->id, parent=[field_parent_name=1], sort=-field_parent_sort_name");

// Attempt 3
$result = $pages->find("template=template_children_name, field_children_name=$page->id, parent=[field_parent_name=1, sort=-field_parent_sort_name]");

// Attempt 4
$parents = $pages->find("template=template_parent_name, template_children_name.field_children_name=$page->id, field_parent_name=1, sort=-field_parent_sort_name"); // $parents are sorted
// Attempt 4.1
$result = $pages->find("template=template_children_name, parent=$parents"); // Not sorted as $parents
// Attempt 4.2
$result = $pages->find("template=template_children_name, parent=$parents, sort=parent.-field_parent_sort_name"); // Not sorted as $parents

// And some other attempts
...

What's the issue? How can I sort result by the parent field?

Link to comment
Share on other sites

SOLVED:

// Attempt X
$result = $pages->find("template=template_children_name, field_children_name=$page->id, parent=[field_parent_name=1], sort=-parent.field_parent_sort_name");

A minus sign to put in front of parent at the first attempt: sort=-parent.field_parent_sort_name

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

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...