Skip to content

ACF Block in multisite switch_to_blog not working properly #2833

Closed Answered by gchtr
mccomaschris asked this question in Q&A
Discussion options

You must be logged in to vote

This is expected behavior. If you use switch_to_blog(), you need to prepare your data in a context variable.

The reason you need to prepare your data in advance is that certain methods in Timber will call WordPress functions that rely on the current blog. Timber doesn’t fill out all data in {{ post }} for performance reasons. For example, {{ post.link }} will call get_permalink() internally, and this will always try to get the data from the current blog.

The solution looks like this:

block/news.php

function herdpress_moments_block( $block, $content = '', $is_preview = false ) {
	$context               = Timber::context(); // phpcs:ignore
	$context['block']      = $block;
	$context['fields']…

Replies: 3 comments

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by mccomaschris
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants