Support

Account

Home Forums Gutenberg How to parse_blocks with a repeater/subfields?

Unread

How to parse_blocks with a repeater/subfields?

  • I’m working on a custom block and I wold like to parse data from that block on the homepage. The issue I have is that I cannot show data from subfields inside a repeater. I’m using the parse_blocks like this:

    function get_daily_training_date()
    {
    	$sections = array();
    
    	global $post;
    	$blocks = parse_blocks($post->post_content);
    	foreach ($blocks as $block) {
    		if ('acf/trainingevent' !== $block['blockName'])
    			continue;
    
    		$daily_dates = '';
    
    		if (!empty($block['attrs']['data']['daily_trainings']))
    			$daily_dates = $block['attrs']['data']['daily_trainings'];
    
    		$sections[] =  esc_html($daily_dates);
    	}
    
    	if (empty($sections))
    		return;
    
    	foreach ($sections as $section)
    		$dates = date("F", strtotime($section));
    	echo $dates;
    }
Viewing 1 post (of 1 total)

You must be logged in to reply to this topic.