Jump to content

Using "start" in a page selector


a-ok
 Share

Recommended Posts

Does the "start" selector property still work? http://cheatsheet.processwire.com/selectors/built-in-page-selector-properties/start-n/

I am doing the following but doesn't seem to have any bearing...

$articles = $pages->find("template=meet-the-locals-detail, start=3, sort=sort");

I liked modifying the selector query, rather than the results (with slice) as presumably it's a lot more efficient.

Link to comment
Share on other sites

Someone more knowledgeable than me may clarify the why, but it seems you need to combine start with limit.

This is for pagination purposes, and it makes sense in that context. I guess it "could" assume an infinite limit by default, but as I said someone more knowledgeable may point out a good reason why it shouldn't. So just put a limit of whatever large number you feel comfortable and it should work.

This code works for me:

$pl = $pages->find('template=basic-page, start=3, limit=3');

Also, you don't need to set `sort=sort`, that's the default behaviour (see correction below). However if these pages you're grabbing are not children of the same page, you'll have a whole new problem to deal with.

  • Like 2
Link to comment
Share on other sites

6 hours ago, heldercervantes said:

Also, you don't need to set `sort=sort`, that's the default behaviour.

Just a correction to this (from the docs):

Quote

How to force pages to sort by their admin order with $pages->find()
Unlike $page->children(), the $pages->find() function does not automatically sort by the order they appear in the site tree. This is because $pages->find() is not limited to finding pages specific to one parent, so it may be pulling pages from multiple places (according to your selector). If your parent page(s) are not already sorting by a specific field, you may still tell the $pages->find() to sort by the parent's order by specifying "sort=sort" in your selector. This is the same as saying "sort by whatever order I dragged the pages to in the admin." But note that if the results have multiple parents, the resulting order isn't likely to be useful.

 

  • Like 2
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...