PHPSpert Posted July 1, 2013 Posted July 1, 2013 It would be nice if ProcessWire had a has() selector like JQuery does. For example, so we could do this: $pages->get("template=accounts")->has("created<=" . strtotime("-1 days")); Is there something like that already or has it not been added?
PHPSpert Posted July 2, 2013 Author Posted July 2, 2013 $pages->get("template=accounts, created<=-1 day"); Understood, but what if you want to get a page with children with a specific attribute? Maybe more specifically: $pages->get("template=accounts")->hasChild("created<=" . strtotime("-1 days"));
Martijn Geerts Posted July 2, 2013 Posted July 2, 2013 maybe: $pages->find("parent.template=accounts, created<=-1 day"); Didn't read your post very well
Soma Posted July 2, 2013 Posted July 2, 2013 $pages->find('created<=yesterday')->first()-> parent() 6
MatthewSchenker Posted July 2, 2013 Posted July 2, 2013 Greetings, Soma! I didn't know this was possible... Thanks for pointing this out. Just another example of how, with ProcessWire, you just need to ask the question to get a (great) answer. Thanks, Matthew 1
diogo Posted July 2, 2013 Posted July 2, 2013 $pages->find('created<=yesterday')->first()->parent() or shorter: $pages->get('created<=yesterday')->parent() Edit: but these will return only the parent of one of the pages created in that time, not all of them. 1
ryan Posted July 3, 2013 Posted July 3, 2013 I think that these guys posted the best solutions for what you are trying to do, since they cause the operation to take place before page is actually loaded. But if you do have a need for a comparison function such as that, you can use $page->is("selector") or $page->matches("selector"); which are similar to what you were looking for with a has() method. When used with a selector, both of the functions do the same thing. The only difference with is() is that you can also send it a template name, like $page->is("product"); or a status like $page->is(Page::statusHidden). Both functions return a boolean true or false.
PHPSpert Posted July 4, 2013 Author Posted July 4, 2013 $pages->find('created<=yesterday')->first()-> parent() I seriously didn't know this was possible. I guess if you're looking for a parent from multiple levels you could do $pages->find('created<=yesterday')->parents()->get("template=top"); // This obj exists so that means the children exist... NICE!
Soma Posted July 4, 2013 Posted July 4, 2013 You can also use the last get() selector inside the parents() and remove get() on the end. It new in 2.3 to use selector with parents in think and you can now also use closest(selector). But using find() in your example and then parents() will not work because find always returns a page array and parents needs one page object. Instead of find you could use a get() like diogo showed.
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