I am migrating a site from a page builder to a block theme.
In my main post template I want to list other posts in the same category as the current post, excluding the current post itself.
In the page builder, filtering the equivalent blog post list was simple a case of choosing 'current category' from a dropdown, but it's not supported in the default Wordpress Query Loop block.
I was hoping to build a block variation for the Query Loop block but have been unable to work out what I need to do to automatically filter the results in the block based on the current post's category.
wp.blocks.registerBlockVariation(
'core/query',
{
name: 'related-latest-posts',
title: 'Related Latest Posts',
description: 'Displays related posts',
attributes: {
postsToShow: 3
},
query: {
postType: 'post',
postStatus: 'publish',
orderby: 'date',
order: 'desc',
perPage: 3
}
}
);