Jump to content

Recommended Posts

Posted
$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. 

Posted

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>
Posted

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

Posted (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 by kongondo
Posted
"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)) 

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...