Support

Account

Forum Replies Created

  • My final solution to parse for reusable block data also…

    if ( function_exists( 'get_field' ) ) {
    	$pid = get_post();
    	if ( has_blocks( $pid_content ) ) {
    		$blocks = parse_blocks( $pid->post_content );
    		foreach ( $blocks as $block ) {
    			if ( $block['blockName'] === 'acf/your-block-name' ) {
    				// Access to block data
    			} elseif ( $block['blockName'] === 'core/block' ) {
    				$block_content = parse_blocks( get_post( $block['attrs']['ref'] )->post_content );
    				if ( $block_content[0]['blockName'] === 'acf/your-block-name' ) {
    					// Access to "some" block data
    				}
    			}
    		}
    	}
    }
  • Are you looking for something like this? The below would give you the data of each block item on the page and you can filter through them based on blockName or other information to target only ACF blocks.

    if ( function_exists( 'get_field' ) ) {
    	$pid = get_post();
    	if ( has_blocks( $pid_content ) ) {
    		$blocks = parse_blocks( $pid->post_content );
    		foreach ( $blocks as $block ) {
    			var_dump( $block );	
    		}
    	}
    }

    Keep in mind if you’re using reusable blocks the information isn’t included and only the ref ID is. I’m currently trying to get the ACF data from a ref ID so I can limit something in my footer from displaying unless the block exists on the page.

  • This issue has also come up for me. I’ve tested both the Duplicate Post and Duplicate Page plugins but the block content doesn’t get duplicated… Just the empty block exists on the new post or page.

    Has anyone had success in fixing this issue?

Viewing 3 posts - 1 through 3 (of 3 total)