arpeekay Posted February 6, 2014 Share Posted February 6, 2014 $features = $pages->get('/restaurant/features/')->children; foreach($features as $feature){ if(!$input->post[$feature->name]){$features->remove($feature);} } if(count($features) > 0){ $restaurants = $pages->find("restaurant_features=$features") } This code returns the pages where one condition is met. I need it to only return the pages where ALL conditions are met. The query ends up look like so: "template=restaurant_features=1052|1053|1054|1115" Not sure where to go from here, any help would be greatly appreciated. Link to comment Share on other sites More sharing options...
Gayan Virajith Posted February 7, 2014 Share Posted February 7, 2014 Hi, Welcome to the forum... May be something like this would help you: <?php //Fetch results from restaurant/features where page id mixed $parentPages = wire('pages')->find("parent=/restaurant/features, id=1052|1053|1054|1115, sort=sort"); ?> <ul> <?php foreach($parentPages as $childPage): ?> <li> <a href="<?php echo $childPage->url?>"> <?php echo $childPage->title; ?> </a> </li> <?php endforeach; ?> </ul> Link to comment Share on other sites More sharing options...
Pete Posted February 7, 2014 Share Posted February 7, 2014 Try if(!$input->post->{$feature->name}) Link to comment Share on other sites More sharing options...
arpeekay Posted February 7, 2014 Author Share Posted February 7, 2014 Got it working. Instead of using an array I just had to check each feature in its own query "template=restaurant_features=1052|1053|1054|1115" will return restaurants with any of those features vs "template=restaurant_features=1052, restaurant_features=1053, restaurant_features=1054, restaurant_features=1115" will return restaurants with ALL of those features Link to comment Share on other sites More sharing options...
kongondo Posted February 7, 2014 Share Posted February 7, 2014 (edited) Hi arpeekay, Welcome to ProcessWire and the forums... Yes, you are right. PW uses "," [i.e. a comma] as AND. The pipe symbol | is used just like in normal PHP "OR". http://processwire.com/api/selectors/#or-selectors1 - OR http://processwire.com/api/selectors/#and-selectors - AND But maybe there is a prettier way of writing those long AND conditions? - just wondering.... Edited February 7, 2014 by kongondo Link to comment Share on other sites More sharing options...
ryan Posted February 8, 2014 Share Posted February 8, 2014 "template=restaurant_features=1052|1053|1054|1115" This isn't a valid selector. I'm guessing just a typo and you mean something like this? template=restaurant, features=1052|1053|1054|1115 Quoting Pete: if(!$input->post->{$feature->name}) You can also do this: if(!$input->post($feature->name)) 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