I am trying to add php to filter the date output format in some dynamic text in a GB query loop. But for some reason, when I add the code for the filter, the front-end pulls up the post date instead of the custom date field. What might I be doing wrong?
See the code I am trying to use to filter below:
/* GenerateBlocks Dynamic Content Output Filter for Event Date */
add_filter( 'generateblocks_dynamic_content_output', function( $content, $attributes ) {
if ( 'post-meta' === $attributes['dynamicContentType'] && isset( $attributes['metaFieldName'] ) ) {
// Change start_date to your meta field name.
if ( 'event_date' === $attributes['metaFieldName'] ) {
return sprintf(
'<time datetime="%1$s">%2$s</time>',
esc_attr( get_the_date( 'c', $id ) ),
esc_html( get_the_date( 'l F j, Y', $id ) )
);
}
}
return $content;
}, 10, 2 );