Jump to content

Order by associated pages


Recommended Posts

I have a category template and each page can be associated with multiple categories using a page field type.

i have this in php : - 

$categories = $pages->find("template=category, limit=6");

I want to sort the results by the amount of pages each category has, is there a way to do this in a selector or is there a better way of doing this?

Link to comment
Share on other sites

In the end i did it by getting all the categories adding a count property and then sorting and limiting after. Not sure what impact this will have on speed as it's getting all the categories first.

$categories = $pages->find("template=category");
foreach($categories as &$category) {
	$count = count($pages->find("template=tour,type=".$category->name));
	$category->tours = $count;


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...