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 🙂
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.