Display posts from another site (multisite) with Query Loop block
-
Hi everyone,
I’m working on a WordPress multisite setup and I’m trying to figure out if it’s possible to display posts from another site within the network using the Query Loop block in the Block Editor (Gutenberg).
For example, from site A, I’d like to show posts published on site B, ideally filtered by post type or category. I know that in PHP this can be achieved with
switch_to_blog()(as explained in this helpful guide by Rudrastyh), but I’m not sure how (or if) this could be integrated into a block-based workflow, especially using the Query Loop block.I was considering extending the Query Loop block itself, as outlined in the documentation here:
https://developer.ww.wp.xz.cn/block-editor/how-to-guides/block-tutorial/extending-the-query-loop-block/. But in that case, I’m not sure how to restore the current blog properly after rendering. I assume I’d need a kind ofpost_render_blockhook for cleanup, which doesn’t seem to exist.Also, on the Editor side, I’m not sure whether it’s even possible to filter the REST API to fetch posts from another site in the network. Has anyone tried something like this?
Maybe building a custom block would be easier to manage in this case. I’m open to suggestions.
Thanks
The topic ‘Display posts from another site (multisite) with Query Loop block’ is closed to new replies.