eangulo Posted January 11, 2018 Share Posted January 11, 2018 Hello, I passed through a lot of documentation about selectors and a few post in the forum but and I did not find my answer so I'll try here :). Question: Is there a way to find pages that have a certain field attached to his template ? Use case: // Site structure Products Computers Computer #1 (has field cached_details) Computer #2 (has field cached_details) Electronics Test #1 Pet Supplies Test #2 (has field cached_details but is empty) // If I want to get all children of page "products" that contains the field "cached_details" I would do something like this // $products => PageArray $results = $products->children("has_field=cached_details"); // or this $results = $products->children("cached_details!=null"); // Expected: $results would contains [Computer #1, Computer #2, Test #2] // Instead I have to do this $results = new PageArray(); foreach($products->children as $child) { if ($child->hasField("cached_details") === true) { $results->add($child); } } Thank you in advance guys :), Link to comment Share on other sites More sharing options...
adrian Posted January 11, 2018 Share Posted January 11, 2018 3 Link to comment Share on other sites More sharing options...
eangulo Posted January 11, 2018 Author Share Posted January 11, 2018 Thank you @adrian my code is more beautiful now ! 1 Link to comment Share on other sites More sharing options...
adrian Posted January 11, 2018 Share Posted January 11, 2018 Just now, eangulo said: Thank you @adrian my code is more beautiful now ! Don't forget to thank @Robin S - it was his idea Link to comment Share on other sites More sharing options...
eangulo Posted January 11, 2018 Author Share Posted January 11, 2018 Yes, of course, my bad Thank you @Robin S ! 1 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