Skip to content

Commit

Permalink
add orderby param in php
Browse files Browse the repository at this point in the history
  • Loading branch information
ntsekouras committed Sep 1, 2020
1 parent 10644f2 commit 5ebbd9e
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 16 deletions.
1 change: 1 addition & 0 deletions packages/block-library/src/query-loop/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ function render_block_core_query_loop( $attributes, $content, $block ) {
'post_type' => 'post',
'offset' => isset( $block->context['query']['perPage'] ) ? ( $block->context['query']['perPage'] * ( $page - 1 ) + $block->context['query']['offset'] ) : 0,
'order' => isset( $block->context['query']['order'] ) ? strtoupper( $block->context['query']['order'] ) : 'DESC',
'orderby' => isset( $block->context['query']['orderBy'] ) ? $block->context['query']['orderBy'] : 'date',
);
if ( isset( $block->context['query']['categoryIds'] ) ) {
$query['category__in'] = $block->context['query']['categoryIds'];
Expand Down
3 changes: 2 additions & 1 deletion packages/block-library/src/query/block.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
"pages": 1,
"offset": 0,
"categoryIds": [],
"order": "desc"
"order": "desc",
"orderBy": "date"
}
}
},
Expand Down
31 changes: 16 additions & 15 deletions packages/e2e-tests/fixtures/blocks/core__query.json
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
[
{
"clientId": "_clientId_0",
"name": "core/query",
"isValid": true,
"attributes": {
"query": {
"perPage": 3,
"pages": 1,
"offset": 0,
{
"clientId": "_clientId_0",
"name": "core/query",
"isValid": true,
"attributes": {
"query": {
"perPage": 3,
"pages": 1,
"offset": 0,
"categoryIds": [],
"order": "desc"
}
},
"innerBlocks": [],
"originalContent": ""
}
"order": "desc",
"orderBy": "date"
}
},
"innerBlocks": [],
"originalContent": ""
}
]

0 comments on commit 5ebbd9e

Please sign in to comment.