Skip to content

Commit

Permalink
Override post-template to support orderby rand #33
Browse files Browse the repository at this point in the history
  • Loading branch information
bobbingwide committed Jun 25, 2021
1 parent 8de77de commit 0022420
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions includes/post-template.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php
/**
* Overrides core/post-template
*
* Hack until a solution is delivered in Gutenberg.
*
* @param $attributes
* @param $content
* @param $block
* @return string
*/
function thisis_render_block_core_post_template( $attributes, $content, $block ) {
$block = thisis_post_template_fiddle( $attributes, $content, $block );
$html = gutenberg_render_block_core_post_template( $attributes, $content, $block );
return $html;
}

/**
* Fiddles the query to support orderby=rand when the className is "rand".
*
*/
function thisis_post_template_fiddle( $attributes, $content, $block ) {
$className = isset( $attributes['className']) ? $attributes['className'] : null;
if ( $className && 'rand' === $className ) {
$block->context['query']['orderBy'] = $className;
}
//bw_trace2();
return $block;
}

0 comments on commit 0022420

Please sign in to comment.