Support

Account

Home Forums Gutenberg Display a post's field value in a Gutenburg block Reply To: Display a post's field value in a Gutenburg block

  • No idea if this helps, but I recently had to get a CPTs ACF metafields displayed in an ACF Block. This is what I put in the blocks template:

    $eventdate = get_post_meta( get_the_ID(), 'client_event_date', true );
    $eventstarttime = get_post_meta( get_the_ID(), 'client_event_starting_time', true );
    $eventendtime = get_post_meta( get_the_ID(), 'client_event_ending_time', true );
    $eventtype = get_post_meta( get_the_ID(), 'client_event_type', true );
    
    if( $eventdate ) {
    	$eventdate = strftime('%A, %d. %B %Y', strtotime($eventdate));
    	
    	echo '<div class="eventdate"><h4>';
        echo $eventdate;
    	if ( $eventstarttime ) { 
    		$eventstarttime = strftime('%R', strtotime($eventstarttime));
    		echo ', from ' . $eventstarttime;}
    	if ( $eventendtime ) { 
    		$eventendtime = strftime('%R', strtotime($eventendtime));
    		echo ' to ' . $eventendtime; }
    		echo '</h4></div>';
    	if ( $eventtype ) {
    		
    	}
    } ?>

    Note that this is obviously rendered identically in the editor as on the frontend – which is the reason I’m browsing these forums, trying to find a way to reliably change a Blocks output when in the Block editor 🙂