Skip to main content
added 76 characters in body
Source Link

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 this, filtering the equivalent blog post list was a simple choicea 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
    }
}

);

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 this was a simple choice from a dropdown but it's not supported in the default 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
    }
}

);

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
    }
}

);

Source Link

How can I filter Query Loop to show only posts in current category?

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 this was a simple choice from a dropdown but it's not supported in the default 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
    }
}

);