Building a multisite where ACF Gutenberg blocks can either pull from main site, or if a priority flag is marked, pulls block fro

admin2025-05-31  5

I'm building a Wordpress multisite where there is a parent site, Site A, which will have several subsites, Site X, Y, Z.

Each site will have the same pages with the same page slugs, and almost the exact same content. I want to write it to where, if there is a change on a page at the parent site, Site A, that change will filter down th the subsites, Sites X, Y, Z, unless the specific gutenberg block is flagged by an ACF field marked 'priority'.

This is the code i have so far:

$slug = $post->post_name;
switch_to_blog( 1 );
$post_exists = get_page_by_path( $slug, OBJECT, 'page' );
$baseblocks  = [];
$microblocks = [];
$finalblocks = [];
if($post_exists){
    setup_postdata($post_exists);
    if ( has_blocks( $post->post_content ) ) {
        $baseblocks = parse_blocks( $post->post_content );
    }
}
restore_current_blog();
wp_reset_postdata();
if ( has_blocks( $post->post_content ) ) {
    $microblocks = parse_blocks( $post->post_content );
}

$microi = 0;
foreach($microblocks as $microblock){
    if(isset($microblock['attrs']['data'])){
        if(isset($microblock['attrs']['data']['priority'])){
            if($microblock['attrs']['data']['priority'] == true){
                render_block($microblock);
            }else{
                render_block($baseblocks[$microi]);
            }
        };
    }
    $microi++;
};

But nothing is rendering, and no errors are throwing. What am I doing wrong?

转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1748643136a313730.html

最新回复(0)