-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Issue #24 - add query block override to order by rand
- Loading branch information
1 parent
7b5051d
commit 79e8d7e
Showing
2 changed files
with
31 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?php | ||
/** | ||
* Overrides core/query-loop. | ||
* | ||
* Hack until a solution is delivered in Gutenberg. | ||
* | ||
* @param $attributes | ||
* @param $content | ||
* @param $block | ||
* @return string | ||
*/ | ||
function thisis_render_block_core_query_loop( $attributes, $content, $block ) { | ||
$block = thisis_query_loop_fiddle( $attributes, $content, $block ); | ||
$html = gutenberg_render_block_core_query_loop( $attributes, $content, $block ); | ||
return $html; | ||
} | ||
|
||
/** | ||
* Fiddles the query to support orderby=rand when the className is "rand". | ||
* | ||
*/ | ||
function thisis_query_loop_fiddle( $attributes, $content, $block ) { | ||
$className = isset( $attributes['className']) ? $attributes['className'] : null; | ||
if ( $className && 'rand' === $className ) { | ||
$block->context['query']['orderBy'] = $className; | ||
} | ||
//bw_trace2(); | ||
return $block; | ||
} |