Jump to content
psy

[solved] Multi-choice select options field selector

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.

 

Share this post


Link to post
Share on other sites

Something like category=Business|Individual ?

But isn't your third choice does what you're after?

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

Thanks @tpr I'm sure the answer is in there somewhere. ProcessWire & Google searched but that page didn't come up

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...