GB 1.5.1 Filter Difficulties

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 );

Hi @clariiosolutions

So, if you have your date set as a Post meta as such: Edit Page “Generated Homepa...

You can add class my-date to this Block: Edit Page “Generated Homepa...

Then, with this PHP snippet, you should be able to format the date:

add_filter('generateblocks_dynamic_content_output', function($content, $attributes, $block){
	if ( ! empty( $attributes['className'] ) && strpos( $attributes['className'], 'my-date' ) !== false ) {
		$timestamp = strtotime($content);
		
		$my_date = sprintf(
		'<time datetime="%1$s">%2$s</time>',
		date('c', $timestamp),
		date('l F j, Y', $timestamp) );
		return $my_date;
	}
	return $content;
}, 10, 3);

Adding PHP reference: Adding PHP - Documentation

Hope this helps!

Thank you! That PHP snippet and adding the CSS class seem to have worked! I appreciate it!

You’re welcome @clariiosolutions!