ProcessWire - Selectors: Unterschied zwischen den Versionen
| Zeile 59: | Zeile 59: | ||
$items = $users->find("roles=superuser"); | $items = $users->find("roles=superuser"); | ||
| + | |||
| + | == Array Selectors == | ||
| + | https://processwire.com/blog/posts/processwire-3.0.13-selector-upgrades-and-new-form-builder-version/#building-a-selector-string-with-user-input-example | ||
Version vom 13. September 2018, 19:44 Uhr
Operatoren
http://cheatsheet.processwire.com/selectors/selector-operators/
Beispiele
Selektoren in Option Fieldtypes
$optionsfield // return id (string)
$optionsfield->id; // return id (int)
$optionsfield->title; // return string USE THIS or
$optionsfield->value; // return empty string or value (if your option settings like '1=value|title')
// dot syntax in selector string
$pages->find('optionsfield.id=2');
Seiten finden
$skyscrapers = $pages->find("template=skyscraper, sort=-modified");
foreach($skyscrapers as $skyscraper) {
echo "<li><a href='$skyscraper->url'>$skyscraper->title</a></li>";
}
Page Reference auf diese Seite
https://processwire.com/talk/topic/1071-page-fieldtype-two-way-relation/
echo $pages->find("field1=$page")->render();
If the page isn't part of the front-end site, then I'll remove view access from its template. Or if it is part of the front-end, but I don't want to show the relations, then this:
if($page->editable()) echo $pages->find("field1=$page")->render();
Though I almost always integrate these relation-revealing pages into the site structure, as it's rare that this information doesn't have some value to the site's users too. This is an example of one that locates all pages referencing it in a field called 'country':
https://www.tripsite.com/countries/croatia/
Punkt Syntax
$architects = $pages->find("template=architect, city.title=Chicago");
$buildings = $pages->find("architect=$architects");
That's easy enough, but wouldn't it be nicer if you could just do this?
$buildings = $pages->find("architect.city.title=Chicago");
$buildings = $pages->find("architect.city.state.abbr=IL");
Broadening further, perhaps we want buildings from all architects in the USA:
$buildings = $pages->find("architect.city.state.country.abbr=USA");
Or perhaps both USA and Canada:
$buildings = $pages->find("architect.city.state.country.abbr=USA|CA");
User
http://cheatsheet.processwire.com/users/users-methods/users-find-selector/
Find all users whose email address ENDS with processwire.com and create a link to email them
$items = $users->find("email$=processwire.com");
foreach($items as $item) {
echo "<li><a href='mailto:{$item->email}'>{$item->name}</a></li>";
}
Find all users who have "fred" anywhere in their name
$items = $users->find("name*=fred");
Find all users who have the "superuser" role
$items = $users->find("roles=superuser");