Wrong post date with events

I use the wp-events manager plugin for managing events.

But when displaying the post date, Cornerstone shows me the event date instead of the post date although it is actually correct in the looper.

I use {{dc:post:publish_date}} for the publish date in the metabox. (The date just above the Consumer Debugger icon. - 19. August 2023)

screenshot 1

You can see that the post_date should be the (3. April 2023) not the event date. The event date is a custom post meta entry and shouldn’t be returned by the {{dc:post:publish_date}}!

I found the “issue”:

The event manager overrides the get_the_date hook

//Override post template tags
	add_filter('get_the_date',array('EM_Event_Post','the_date'),10,3);
...
public static function the_date( $the_date, $d = '', $post = null ){
		$post = get_post( $post );
		if( $post->post_type == EM_POST_TYPE_EVENT ){
			$EM_Event = em_get_event($post);
			if ( '' == $d ){
				$the_date = $EM_Event->start()->i18n(get_option('date_format'));
			}else{
				$the_date = $EM_Event->start()->i18n($d);
			}
		}
		return $the_date;
	}
...
public function start( $utc_timezone = false ){
		return apply_filters('em_event_start', $this->get_datetime('start', $utc_timezone), $this);
	}

And you use this function too! (…/class-dynamic-content-post.php)

 case 'publish_date':
        $result = get_the_date( isset( $args['format'] ) ? $args['format'] : get_option('date_format'), $post->ID );

Well, in my opinion WP-Event Manger acts wrong, because according to WordPress codex with the function get_the_date should actually always be delivered the post date and not the date of the event.

On the other hand, I also expect from Cornerstone to always provide the publish date with {{dc:post:publish_date}} shortcode.

1 Like

I have already written to Events Manager support!

Until then, for all those who have the same problem, with this we override the “get_the_date” hook again.

add_filter ('get_the_date', 'post_correct_postdate', PHP_INT_MAX, 3);
function post_correct_postdate ($the_date, $format, $post )
{
	
	if (empty($format))
	{
		$the_date = date_i18n (get_option('date_format'), strtotime($post->post_date));
	}
	else
	{
		$the_date = date_i18n ($format, strtotime($post->post_date));
	}

	return $the_date;
}
1 Like

Thanks for your notes. I have saved this filter in case our team needs to use it. I’m not entirely sure we’ll ever have this in the main codebase, but I’ll keep it in mind. Have a great day!

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.