psy Posted April 1, 2019 Share Posted April 1, 2019 I have a select options field that displays as multi-choice checkboxes. It's a required field and some pages have only one option selected, other pages have both selected, eg: Page 1: category = Business Page 2: category = Individual Page 3: category = Business and Individual Dilemma arises when I try to select pages that have both 'Business' and 'Individual' This codes works if I only want one choice: if ($page->id == 1055) { $services = $pages->get(1115)->children("category=Business"); } elseif ($page->id == 1113) { $services = $pages->get(1115)->children("category=Individual"); } BUT both $services result sets leave out Page 3. So I tried the following using the 'contains' selector which caused a page crash: if ($page->id == 1055) { $services = $pages->get(1115)->children("category*=Business"); } elseif ($page->id == 1113) { $services = $pages->get(1115)->children("category*=Individual"); } Any suggestions on how to write the selector to successfully retrieve pages that have both choices? Thanks psy Solution: The selector retrieves the value/id, not the title of the option if multiple, eg "1|2" rather than "Business|Individual". Changed it to: if ($page->id == 1055) { $services = $pages->get(1115)->children("category=1"); } elseif ($page->id == 1113) { $services = $pages->get(1115)->children("category=2"); } This covered the and/or scenario. Link to comment Share on other sites More sharing options...
tpr Posted April 1, 2019 Share Posted April 1, 2019 Something like category=Business|Individual ? But isn't your third choice does what you're after? Link to comment Share on other sites More sharing options...
psy Posted April 1, 2019 Author Share Posted April 1, 2019 Thanks @tpr 33 minutes ago, tpr said: Something like category=Business|Individual ? But won't that give me all pages? On the Business page, I only want to show pages that have 'Business' checked, whether on it's own or also checked with 'Individual'. What was my third choice? Only showed two ? Second choice doesn't work via the API on select options fields Link to comment Share on other sites More sharing options...
tpr Posted April 1, 2019 Share Posted April 1, 2019 3rd choice: sorry, I was on mobile and I miscread page 3 to choice 3 ? I guess you could use OR groups here: https://processwire.com/docs/selectors/#or-groups 2 Link to comment Share on other sites More sharing options...
psy Posted April 1, 2019 Author Share Posted April 1, 2019 Thanks @tpr I'm sure the answer is in there somewhere. ProcessWire & Google searched but that page didn't come up Link to comment Share on other sites More sharing options...
Robin S Posted April 1, 2019 Share Posted April 1, 2019 The syntax works for me to match pages with multiple options selected: Do you have values and titles defined separately for your Options field? If so you probably want to include the subfield in your selector: category.title or category.value 2 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