Home › Forums › Gutenberg › redering block via ajax not working multisite › Reply To: redering block via ajax not working multisite
anyone else having issues with this, I managed to solve this by rewriting the acf_rendered_block()
– so not an ideal solution but it works for now.
<?php
require '../../../../../wp-load.php';
switch_to_blog( 2 );
$ad = ( is_numeric( $_REQUEST['p'] ) ) ? $_REQUEST['p'] : '';
if ( ! empty( $ad ) ) {
$ad = new WP_Query(
array(
'p' => $ad,
'post_type' => 'ad',
)
);
$blocks = parse_blocks( $ad->posts[0]->post_content );
foreach ( $blocks as $block ) {
if ( 'acf/lunchrush-ad' == $block['blockName'] ) {
ob_start();
acf_setup_meta( $block['attrs']['data'], $block['attrs']['id'], true );
if ( file_exists( __DIR__ . '/block-ad.php' ) ) {
$path = __DIR__ . '/block-ad.php';
}
// Include template.
if ( file_exists( $path ) ) {
include( $path );
}
// Reset postdata.
acf_reset_meta( $block['attrs']['id'] );
$return = ob_get_clean();
}
}
if ( ! empty( $return ) ) {
$return = '<div class="ad-preview">' . $return . '</div>';
}
}
echo $return;
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.