Jump to content

[solved] Multi-choice select options field selector


psy
 Share

Recommended Posts

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

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

The syntax works for me to match pages with multiple options selected:

2019-04-02_102433.png.14d1d44febf115cbb4cdd9d4cfe4fbe0.png

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

  • Like 2
Link to comment
Share on other sites

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
 Share

  • Recently Browsing   0 members

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