Skip to content

Commit

Permalink
Support display of related posts using className related on the core/…
Browse files Browse the repository at this point in the history
…post-template block #36
  • Loading branch information
bobbingwide committed Apr 20, 2024
1 parent 10fb5c5 commit 437a28c
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion includes/post-template.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,26 @@ function thisis_render_block_core_post_template( $attributes, $content, $block )
}

/**
* Fiddles the query to support orderby=rand when the className is "rand".
* Fiddles the query depending on the value of the Additional Class(es) field.
*
* Fiddles the query to support orderby=rand when the className is "rand".
* Fiddles the query to support display of posts in the related category/categories when the className is "related"
*/
function thisis_post_template_fiddle( $attributes, $content, $block ) {

$className = isset( $attributes['className']) ? $attributes['className'] : null;
if ( $className && 'rand' === $className ) {
$block->context['query']['orderBy'] = $className;
}

if ( $className && 'related' === $className ) {
bw_trace2();
$post = get_post();
bw_trace2( $post );
$terms = wp_get_post_categories( $post->ID, [ 'fields' => 'ids']);
bw_trace2( $terms, "terms", false );
$block->context['query']['taxQuery']['category'] = $terms;
}
//bw_trace2();
return $block;
}
Expand Down

0 comments on commit 437a28c

Please sign in to comment.