Skip to content

Querying & Rendering in Templates

Entries exposes its full query and entity API through $wire->entries (or wire()->entries in templates and closures).

site/templates/_init.php
<?php
declare(strict_types=1);
namespace ProcessWire;
$entries = wire()->entries;
// Deterministic Single lookup (or shorthand $entries(GeneralSettingsSingle::class))
$settings = $entries->single('general_settings');
$settings->of(true);
$siteName = $sanitizer->entities((string) $settings->get('site_name'));
// Direct lookup by UUID or "type:slug"
$port = $entries->get('ports:gocek-marina');
// Batch lookup by UUIDs
$selectedPorts = $entries->getMany([$uuid1, $uuid2], 'ports');

$entries->find() returns an EntryArray (extending ProcessWire’s PaginatedArray) supporting =, !=, <, <=, >, >=, *=, %=, ^=, $=, ~=, ~|=, multi-field OR (title|port_code%=gocek), parenthesized OR-groups, sorting, and pagination:

site/templates/rates.php
<?php
declare(strict_types=1);
namespace ProcessWire;
$entries = wire()->entries;
// 1. Multi-hop relational traversal, block subfields, and eager loading (with=)
$rates = $entries->find(
'type=rates, status=published, route.departure_port.country=TR, highlights.title*=Crew, with=route.departure_port, sort=-price, limit=12'
);
// 2. Parenthesized OR-groups and multi-field OR
$featured = $entries->find(
'type=yachts, (category=catamaran, guests>=10), (weekly_rate>=40000), limit=12'
);
$portMatches = $entries->find('type=ports, title|port_code|subtitle%=gocek, limit=20');
// 3. Saved blueprint views (defined under views: in YAML)
$vipYachts = $entries->collection('yachts')->view('vip_fleet', 'limit=12');
$inlineView = $entries->find('type=yachts, view=vip_fleet, limit=12');
// 4. Two-level hierarchical collections (hierarchical: true)
$rootRegions = $entries->find('type=regions, parent_id=0, sort=sort');
foreach ($rootRegions as $region) {
$subRegions = $region->children();
}
Directive Meaning
status=published / status=live Published, non-hidden, non-trashed items inside their active schedule window
status=scheduled / status=expired Future-scheduled or past-expiration publishable items
status=unpublished / status=draft Unpublished draft records
status=hidden / status=trash / status=locked Hidden, trashed, or record-locked items
include=hidden|unpublished|drafts|trash|all Override default live-only filter (include=drafts overlays active working drafts in one batch query)
with=rel1|rel2.nested Batch-preload referenced EntryItem or Page relations
view=<name> Expand a saved blueprint views: preset

Pagination, streaming, and lightweight queries

Section titled “Pagination, streaming, and lightweight queries”
<?php
declare(strict_types=1);
namespace ProcessWire;
$entries = wire()->entries;
// Offset pagination metadata on EntryArray
$pageItems = $entries->find('type=seasons, sort=rate_multiplier, start=0, limit=25');
$total = $pageItems->getTotal();
// Structured paginated payload
$paged = $entries->findPaginated('type=seasons, sort=sort', page: 1, limit: 12);
// Keyset cursor pagination (zero OFFSET for infinite scroll or APIs)
$cursor1 = $entries->findCursor('type=bookings, sort=-created', limit: 25);
$cursor2 = $entries->findCursor('type=bookings, sort=-created', limit: 25, after: $cursor1['nextCursor']);
// Ultra-fast raw arrays or UUID-only lists (zero EntryItem hydration)
$rawRows = $entries->findRaw('type=seasons, sort=sort', ['id', 'title', 'code', 'rate_multiplier']);
$uuids = $entries->queryEngine()->findIds('type=seasons, is_peak=1');
// Memory-safe streaming generator for thousands of rows
foreach ($entries->findMany('type=bookings, include=all', chunkSize: 250) as $booking) {
// Processed in 250-item chunks
}

SQL aggregations, Omni-Search, and bulk mutations

Section titled “SQL aggregations, Omni-Search, and bulk mutations”
<?php
declare(strict_types=1);
namespace ProcessWire;
$entries = wire()->entries;
// Numeric aggregations on indexed fields
$total = $entries->sum('type=charter_rates, season=HIGH_2026', 'weekly_rate');
$avg = $entries->avg('type=charter_rates, season=HIGH_2026', 'weekly_rate');
$min = $entries->min('type=charter_rates', 'weekly_rate');
$max = $entries->max('type=charter_rates', 'weekly_rate');
$byStage = $entries->groupBy('type=charter_inquiries', 'booking_status', 'COUNT');
$currencies = $entries->distinct('type=charter_rates', 'currency');
// Cross-blueprint Omni-Search across singles, collections, and nested blocks
$hits = $entries->search('Gocek', [
'types' => ['ports', 'routes', 'general_settings'],
'kind' => 'all',
'include' => 'published',
'limit' => 20,
]);
// Bulk update matching records
$updated = $entries->updateMany('type=rates, season=low', ['is_discounted' => 1]);
// Exclusive default helpers (for blueprints with exclusive: is_default)
$defaultSeason = $entries->default('seasons');
$entries->setDefault('seasons', $highSeason);
// Deep clone (new UUIDv7, cloned nested blocks, copied isolated media)
$copy = $entries->cloneItem($highSeason, ['code' => 'HIGH_2027', 'title' => 'High Season 2027']);
<?php
declare(strict_types=1);
namespace ProcessWire;
$item->of(true);
if ($item->hasValue('cover_image')) {
$rawDate = $item->getUnformatted('start_date');
$fieldLabel = $item->label('title');
$selectedLabel = $item->optionLabel('hull_type');
$multiLabels = $item->optionLabels('included_extras');
$maskedSecret = $item->markupValue('api_key');
$formatted = $item->formatLabel('', '{title} ({code}) - {departure_port.title}');
// Sparse array projection for JSON/API responses
$payload = $item->toArray(formatted: true, fields: ['title', 'code', 'departure_port.title']);
}
// Referential integrity helpers
$linkedPages = $item->referencingPages('include=all');
$linkedEntries = $item->referencingEntries();
$reverseRoutes = $item->reverse('routes', 'departure_port', 'sort=title');

Wrap critical multi-step entry mutations in $entries->transaction() (with automatic InnoDB deadlock retries) and lock individual items with $entries->getForUpdate():

<?php
declare(strict_types=1);
namespace ProcessWire;
$entries = $this->wire()->entries;
$entries->transaction(function () use ($entries, $itemId): void {
$locked = $entries->getForUpdate($itemId);
if ($locked !== null) {
$locked->set('seats_remaining', max(0, (int) $locked->get('seats_remaining') - 1));
$entries->save($locked);
}
});

Next steps