0

I'd like to create a block to display posts (in my sidebar) from the same category as the current post.

I tried to use a blockVariation on core/query, but I don't know how to pass it the current post's categories (as a prop ?).

Ideally, I'd like to reuse the "Recent Posts" block, modifying its query to filter by category.

My best option would be to generate the list of categories using PHP and pass it as a prop to the component.

(I'm usually a Laravel/VueJS developer, I'm new to this)

registerBlockVariation("core/query", {
  name: VARIATION_NAME,
  title: "LVLUP Example",
  icon: "book",
  description: "Displays a list of same category posts.",
  isActive: ["namespace"],
  attributes: {
    namespace: VARIATION_NAME,
    query: {
      postType: "post",
      perPage: 6,
      offset: 0,
      taxQuery: {
        category: currentPostCategories,
      },
    },
    align: "wide",
    displayLayout: {
      type: "flex",
      columns: 3,
    },
  },
  allowedControls: ["order", "author"],
  innerBlocks: [
    [
      "core/post-template",
      {},
      [["core/post-featured-image"], ["core/post-title"]],
    ],
  ],
  scope: [ 'inserter' ],
});

I believe I got something wrong. Any tips pointing me in the right direction would be appreciated. Thank you !

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.