Support

Account

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;