admin管理员组

文章数量:1122832

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

);

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

);

Share Improve this question edited Apr 16, 2024 at 9:02 J Glasshalfpool asked Apr 16, 2024 at 9:01 J GlasshalfpoolJ Glasshalfpool 112 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 1

Curious if you ever figured this one out? I'm running into a similar situation.

本文标签: categoriesHow can I filter Query Loop to show only posts in current category