chodorowicz Posted February 17, 2011 Share Posted February 17, 2011 I'll admit right away that I've managed to solve it, but maybe someone else will find this useful and also I believe it would be good to put it somewhere in FAQ/Documentation When getting pages by template like so: $categories = $pages->find("template=category"); the results are not sorted according to menu order (maybe it's a bug?). I couldn't find anywhere the info how to force the sort by menu order (everywhere in the documentation there are examples with title and some other variables). The solution was quite easy, but I had to look to database and source code: $categories = $pages->find("template=category,sort=sort"); Btw. thanks for this amazing CMS - I've spent several hours today learning and doing my first website and I must say it is impressive. It has great potential. Cheers. 1 Link to comment Share on other sites More sharing options...
Adam Kiss Posted February 17, 2011 Share Posted February 17, 2011 Hi chodorowicz, welcome to the forums. I agree, 'sort=sort' should be in docs and also there should be info about what sorting is used by default (My personal guess is that it's sorted by internal ID). Also, you can use 'sort=-sort' if you want to reverse the order. Link to comment Share on other sites More sharing options...
ryan Posted February 17, 2011 Share Posted February 17, 2011 Good points. The "sort=sort" is assumed when you use the children() or siblings() functions. But for find() operations, a relevancy sort is introduced. Of course, if your find() doesn't involve some kind of keyword, then that relevancy doesn't really come into play. I think what may be appropriate is for me to automatically add a "sort=sort" to any find() operations that include a "parent=" portion of the selector. What do you think? 1 Link to comment Share on other sites More sharing options...
Adam Kiss Posted February 17, 2011 Share Posted February 17, 2011 I'll just say that it doesn't matter what is default sorting, if you DESCRIBE ALL POSSIBLE VALUES AND WHAT IS DEFAULT VALUE P.S.: Using CAPS because it's os damn inportant to inform in docs what programmer can expect Link to comment Share on other sites More sharing options...
ryan Posted February 17, 2011 Share Posted February 17, 2011 This is covered on the documentation in the API > Selectors section, but wasn't previously at the level of detail you requested. The possible values depend on what fields you've created (they are the values). But I didn't cover the "sort=sort" before, so that's taken care of now. Here is what I added: How results are sorted if you don't specify a "sort" in your selector In $page->children() and $page->siblings() the results are automatically sorted by the page's default sort field that you specify in the admin. If not specified in the admin, the pages will be sorted by the order they are placed in the admin. This behavior can be overridden by specifying your own "sort=[property]". With $pages->find() and $page->find(), if you don't specify your own "sort=[property]", the results are sorted according to MySQL's text searching relevance. If no text searches are performed in your find(), the results are unsorted. As a result, it is generally a good idea to include a "sort=[property]" when using $pages->find(), especially if you care about the order and your find() operation is not text/relevance related. 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. 1 Link to comment Share on other sites More sharing options...
chodorowicz Posted February 20, 2011 Author Share Posted February 20, 2011 This is covered on the documentation in the API > Selectors section, but wasn't previously at the level of detail you requested... Great, thanks for that. I think now it's clear enough. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now