Ajax Driven Dropdown Lists for ProcessWire made easy

Searching/Querying Dynamic Selects Fields

Accessing and outputting the contents of the Dynamic Selects field(s) in your template file requires knowledge of the ProcessWire selector type referred to as Sub-selectors. This is because this field stores IDs of the pages, templates, users or fields of selected options in the dropdowns rather than the raw values themselves.

Assuming we have the following Dynamic Select dropdown and similar ones in other pages ...

Product Type Product Price
Clothes Jeans 100



...we would use the following selector to find the products.

$products = $pages->find("dynamic.product=[title=jeans], dynamic.price=[integer>75]");

In this selector, the sub-selector is enclosed in square brackets []; ProcessWire will run that query first (i.e. evaluate what is between the square brackets first). That query will return an ID of the page that contains the given value. For instance, [title=jeans] will return the ID of the page with the title Jeans. [integer>75] will return the ID of the page whose integer field is greater than 75.

.product and .price are sub-fields in the field dynamic. In other words, the column names in the database table. These also correspond to the names of the select dropdowns.

Internally, ProcessWire will convert the query to dynamic.product=1234, dynamic.price=4567;

However, we can make the selector even more efficient with a query such as this:

$products = $pages->find("dynamic.product!='', dynamic.price=[integer>75, template=products-clothes|products-groceries|products-electronics]");

In the case of a pagefield, using our initial countries, cities, attractions example, we could do something like this:

$results = $pages->find("dynamic.cities!='', dynamic.attractions=[title=Big Ben, template=attractions]");

The most important thing to remember in these examples is that the [fieldName = value] in the square brackets corresponds to our data source=value!