Support

Account

Home Forums Gutenberg Multisite where page content can be prioritized per block?

Unread

Multisite where page content can be prioritized per block?

  • 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?

Viewing 1 post (of 1 total)

You must be logged in to reply to this topic.