Skip to content

Commit

Permalink
Issue #24 - add query block override to order by rand
Browse files Browse the repository at this point in the history
  • Loading branch information
bobbingwide committed May 5, 2021
1 parent 7b5051d commit 79e8d7e
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
4 changes: 2 additions & 2 deletions includes/block-overrides.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/
//require_once __DIR__ . '/query-pagination.php';
//require_once __DIR__ . '/query-pagination-numbers.php';
//require_once __DIR__ . '/query-loop.php';
require_once __DIR__ . '/query-loop.php';
//require_once __DIR__ . '/post-excerpt.php';
//require_once __DIR__ . '/post-content.php';
require_once __DIR__ . '/template-part.php';
Expand All @@ -41,7 +41,7 @@ function thisis_register_block_type_args( $args ) {
//$args = thisis_maybe_override_block( $args,'core/query-pagination', 'render_block_core_query_pagination');
//$args = thisis_maybe_override_block( $args,'core/query-pagination-numbers', 'render_block_core_query_pagination_numbers');

//$args = thisis_maybe_override_block( $args,'core/query-loop', 'render_block_core_query_loop' );
$args = thisis_maybe_override_block( $args,'core/query-loop', 'render_block_core_query_loop' );
//$args = thisis_maybe_override_block( $args,'core/post-excerpt', 'render_block_core_post_excerpt' );
//$args = thisis_maybe_override_block( $args,'core/post-content', 'render_block_core_post_content' );
$args = thisis_maybe_override_block( $args,'core/template-part', 'render_block_core_template_part' );
Expand Down
29 changes: 29 additions & 0 deletions includes/query-loop.php
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;
}

0 comments on commit 79e8d7e

Please sign in to comment.