• I’m trying to create a set of blocks pretty similar to the core Query loop block. I have a few specific modifications that I need to make that probably makes block variations infeasible.

    What I don’t understand about nestd/Inner Blocks is how I’m supposed to use some context from the parent or child blocks. So far, all I know that I can access is the $content variable, but that is only a string of HTML….

    In essence, what I need is a set of blocks that’s something of an abstraction of a standard WordPress post query…

    I have blocks like:

    • Post Loop – Saves the filters and sorting settings as attributes
      • Loop Template – Saves the styles and basic layout of the block as attributes
        • Output Elements: Title/Heading, Post content, etc.
    • This topic was modified 3 weeks, 1 day ago by oguruma.
Viewing 1 replies (of 1 total)
  • Hello @oguruma

    To achieve this, use useBlockProps and useSelect to pass context data from parent to child blocks dynamically in a more advanced setup. Define the main query and filtering logic in the Post Loop block, and use InnerBlocks to render Loop Template and Output Elements within it. In Output Elements, use useSelect to pull query results from the parent context. Alternatively, look into the Block Context API for passing values directly between blocks if you need fine-grained control over attributes.

Viewing 1 replies (of 1 total)
  • You must be logged in to reply to this topic.