How can I render a wp:query nested block dynamically in wordpress

37 Views Asked by At

I want to parse and render the query blocks that woocommerce renders in archive-product.html dynamically.I use Ajax call to run php and render the block.

I tried

$content = '<!-- wp:query {"queryId"...
...
<!-- /wp:query -->'

$blocks = parse_blocks($content);
foreach ($blocks as $block) {
    echo render_block($block);
}

It renders it but it doesn't run the query, so I get no products were found. The block template is copy paste from woocommerce. What am I missing? Thanks

0

There are 0 best solutions below