records_query()
Find records in a table that match a set of filters. Returns a list of records.
Syntax
records_query(table, filters?, options?)
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
table |
string | yes | Table name or database table id. |
filters |
array | no | A list of filter conditions (see below). Omit or pass [] for all records. |
options |
array | no | order, limit, offset (see below). |
Filters
Each filter is ["field" => <field id>, "op" => <operator>, "value" => <value>]. Filters are combined with AND.
| Operator | Meaning |
|---|---|
= |
equals |
!= |
not equal |
> < >= <= |
numeric / date comparison |
contains |
substring match (membership for multi-value fields) |
starts_with |
begins with |
ends_with |
ends with |
is_empty |
field is blank (no value needed) |
is_not_empty |
field has any value (no value needed) |
Options
| Key | Default | Notes |
|---|---|---|
order |
— | e.g. "created_at DESC" |
limit |
100 | clamped to 1–1000 |
offset |
0 | for paging |
Returns
A list (array) of records, each shaped like a record_get() result. Empty list if nothing matches.
Example
$hot = records_query("leads", [
["field" => "status", "op" => "=", "value" => "qualified"],
["field" => "score", "op" => ">", "value" => 80]
], ["order" => "score DESC", "limit" => 25]);
foreach ( $hot as $lead ) {
sys_log($lead["name"] . " — " . $lead["score"]);
}
Example output
[
["name" => "Acme", "score" => 95, "_meta" => ["id" => 12, "title" => "Acme"]],
["name" => "Globex", "score" => 88, "_meta" => ["id" => 7, "title" => "Globex"]]
]
Notes
- For exactly one record, use records_query_one(); to just count, use records_count().
- To reuse a saved view's filters and sort, use records_query_from_view().
See also: records_query_one(), records_count(), records_related()