Skip to content

Commit 8d6cf7a

Browse files
Fix issue #1547 adding support for sorting by non-FieldtypePage fieldtypes that use Page or PageArray, like FieldtypeTable and FieldtypeRepeater
1 parent d3e0ab3 commit 8d6cf7a

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

wire/core/PageFinder.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1059,14 +1059,16 @@ protected function getQuerySortSelector(DatabaseQuerySelect $query, Selector $se
10591059
$subValue = $database->escapeCol($subValue);
10601060
$tableAlias = "_sort_$fieldName". ($subValue ? "_$subValue" : '');
10611061
$table = $database->escapeTable($field->table);
1062+
$blankValue = $field->type->getBlankValue(new NullPage(), $field);
10621063

10631064
$query->leftjoin("$table AS $tableAlias ON $tableAlias.pages_id=pages.id");
10641065

10651066
if($subValue === 'count') {
10661067
// sort by quantity of items
10671068
$value = "COUNT($tableAlias.data)";
10681069

1069-
} else if($field->type instanceof FieldtypePage) {
1070+
// } else if($field->type instanceof FieldtypePage) {
1071+
} else if(is_object($blankValue) && ($blankValue instanceof PageArray || $blankValue instanceof Page)) {
10701072
// If it's a FieldtypePage, then data isn't worth sorting on because it just contains an ID to the page
10711073
// so we also join the page and sort on it's name instead of the field's "data" field.
10721074
if(!$subValue) $subValue = 'name';

0 commit comments

Comments
 (0)