Selector class

Selector maintains a single selector consisting of field name, operator, and value.

  • Serves as the base class for the different Selector types (SelectorEqual, SelectorNotEqual, SelectorLessThan, etc.)
  • The constructor requires $field and $value properties which may either be an array or string. An array indicates multiple items in an OR condition. Multiple items may also be specified by pipe “|” separated strings.
  • Operator is determined by the Selector class name, and thus may not be changed without replacing the entire Selector.
// very basic usage example
// constructor takes ($field, $value) which can be strings or arrays
$s = new SelectorEqual('title', 'About Us');
// $page can be any kind of Wire-derived object
if($s->matches($page)) {
  // $page has title "About Us"
}
// another usage example
$s = new SelectorContains('title|body|summary', 'foo|bar');
if($s->matches($page)) {
  // the title, body or summary properties of $page contain either the text "foo" or "bar"
}

List of core selector-derived classes

  • SelectorEqual
  • SelectorNotEqual
  • SelectorGreaterThan
  • SelectorLessThan
  • SelectorGreaterThanEqual
  • SelectorLessThanEqual
  • SelectorContains
  • SelectorContainsLike
  • SelectorContainsWords
  • SelectorContainsWordsPartial (3.0.160+)
  • SelectorContainsWordsLive (3.0.160)
  • SelectorContainsWordsLike (3.0.160)
  • SelectorContainsWordsExpand (3.0.160)
  • SelectorContainsAnyWords (3.0.160)
  • SelectorContainsAnyWordsPartial (3.0.160)
  • SelectorContainsAnyWordsLike (3.0.160)
  • SelectorContainsExpand (3.0.160)
  • SelectorContainsMatch (3.0.160)
  • SelectorContainsMatchExpand (3.0.160)
  • SelectorContainsAdvanced (3.0.160)
  • SelectorStarts
  • SelectorStartsLike
  • SelectorEnds
  • SelectorEndsLike
  • SelectorBitwiseAnd

Click any linked item for full usage details and examples. Hookable methods are indicated with the icon. In addition to those shown below, the Selector class also inherits all the methods and properties of: WireData and Wire.

Show class?             Show args?        

Common

NameReturnSummary 
Selector::field()
string array nullGet the field(s) of this Selector
Can also be used as property: Selector::field
 
Selector::fields()
arrayReturn array of field(s) for this Selector
Can also be used as property: Selector::fields
 
Selector::get(string $key)
array mixed null stringGet a property 
Selector::getCompareType()
intWhat type of comparson does Selector perform? 
Selector::getDescription()
stringGet longer description that describes this Selector 
Selector::getLabel()
stringGet short label that describes this Selector 
Selector::matches($value)
boolDoes this Selector match the given value? 
Selector::operator()
stringReturn the operator used by this Selector
Can also be used as property: Selector::operator
 
Selector::set(string $key, mixed $value)
Selector WireDataSet a property of the Selector 
Selector::setField($field)
selfSet field or fields 
Selector::setValue($value)
selfSet selector value(s) 
Selector::value()
string array nullGet the value(s) of this Selector
Can also be used as property: Selector::value
 
Selector::values()
arrayReturn array of value(s) for this Selector
Can also be used as property: Selector::values
 

Properties

NameReturnSummary 
Selector::altOperators array Alternate operators to use when primary fails match, supported only by compareTypeFind. Since 3.0.161 (default=[])  
Selector::forceMatch null bool When boolean, forces match (true) or force non-match (false). (default=null)  
Selector::group string null Group name for this selector (if field was prepended with a "group_name@").  
Selector::not bool Is this a NOT selector? Indicates the selector returns the opposite if what it would otherwise.  
Selector::quote string Type of quotes value was in, or blank if it was not quoted. One of: '"[{(  
Selector::str string String value of selector, i.e. “a=b”.  

Additional methods and properties

In addition to the methods and properties above, Selector also inherits the methods and properties of these classes:

API reference based on ProcessWire core version 3.0.236

Latest news

  • ProcessWire Weekly #518
    The 518th issue of ProcessWire Weekly brings in all the latest news from the ProcessWire community. Modules, sites, and more. Read on!
    Weekly.pw / 13 April 2024
  • ProFields Table Field with Actions support
    This week we have some updates for the ProFields table field (FieldtypeTable). These updates are primarily focused on adding new tools for the editor to facilitate input and management of content in a table field.
    Blog / 12 April 2024
  • Subscribe to weekly ProcessWire news

“…building with ProcessWire was a breeze, I really love all the flexibility the system provides. I can’t imagine using any other CMS in the future.” —Thomas Aull