Jump to content

Checkbox Reversed – select all pages where a checkbox is checked


Recommended Posts

Posted

Hi all,

when using the following selector, ProcessWire finds all pages, not only those with the CheckboxReversed "checkbox_export" checked.

$ps = pages()->find('checkbox_export!=1, sort=id, include=hidden, status<' . Page::statusTrash);
foreach($ps as $p){
    var_dump($p->title);   
}

As a workaround I added the following condition:

$ps = pages()->find('checkbox_export!=1, sort=id, include=hidden, status<' . Page::statusTrash);
foreach($ps as $p){
    if ($p->hasField('checkbox_export')) var_dump($p->title);   
}

I wonder if there is any "native" selector technique, where you can check if a field exists on a page. Something like "has_field", but that does not exists. At least I found nothing in the docs.

Does anyone know the trick, if there is any?

  • Like 1
Posted

There's no direct selector option, but you could get all templates that use the field first, then use those in the selector. Unless you use the field in repeaters or related types, fieldgroup name = template name.

$tpls = $fields->get('checkbox_export')->getFieldgroups()->implode('|', 'name');
$ps = pages()->find("template=$tpls, checkbox_export!=1, sort=id, include=hidden, status<" . Page::statusTrash);

 

  • Like 1
  • Thanks 1

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