Modern Event Calendar (aka MEC) - Single Event Template Page with Bricks Builder

Hi :slight_smile:

I’m trying to create a new single event template for MEC for my client and I’m struggling to bypass the default template provided by Modern Event Calendar plugin.

I have selected the type of posts, Events. But it doesn’t work as expected :frowning:

Does anyone know how to do this ? Is it possible ?

Thanks in advance !

Cheers !

Hi gents :slight_smile:

If you are interrested, this is my solution to my problem:

Create a single-mec-events.php file into my child theme folder with this:

<?php
/** no direct access **/
defined('MECEXEC') or die();
?>

<?php get_header(); ?>

<?php
$post_id = get_the_ID();
?>
<?php 
    echo do_shortcode('[bricks_template id="1222"]');
?>

<?php get_footer(); ?>

Edit you Bricks template section with bricks and include all elements you need with the help of this link: Overriding Single Event Page - MEC Knowledgebase

Sometimes it’s possible to call data from the get_post_meta, like:

get_post_meta( get_the_ID(), 'mec_start_date', true );

Sometimes, you have to use the code from Webnus like:

<?php
$single = new MEC_skin_single();
$single_event_main = $single->get_event_mec(get_the_ID());
$single_event_obj = $single_event_main[0];

$single->display_organizer_widget($single_event_obj);

?>

After that, with a little bit of CSS, it’s possible to adapt the layout for your needs.

Hope this help MEC users with Bricks.

Cheers.

Thanks @Sebastien for your share. I started out with it and let ChatGPT create a single-mec-events.ph for me.

What I have now is:

<?php
/** no direct access **/
defined('MECEXEC') or die();
?>

<?php get_header(); ?>

<?php

$single = new MEC_skin_single();

$single_event_main = $single->get_event_mec(get_the_ID());
$single_event_obj = $single_event_main[0];

$title = $single_event_obj->data->title;
$thumbnail = $single_event_obj->data->thumbnails['full'];
$content = $single_event_obj->data->content;


$start_date = get_post_meta( get_the_ID(), 'mec_start_date', true );
$end_date = get_post_meta( get_the_ID(), 'mec_end_date', true );
$event_link = get_permalink( get_the_ID() );
$start_hour = get_post_meta( get_the_ID(), 'mec_start_time_hour', true );
$start_minute = get_post_meta( get_the_ID(), 'mec_start_time_minutes', true );
$end_hour = get_post_meta( get_the_ID(), 'mec_end_time_hour', true );
$end_minute = get_post_meta( get_the_ID(), 'mec_end_time_minutes', true );


echo do_shortcode('[bricks_template id="1363"]');
?>
<?php get_footer(); ?>

With that code I can access the title, content-text and image with
{post_title}
{featured_image}
{post_content}

But I can’t figure out how to get the dates, times and link into Bricks. Any ideas?

Managed to solve it…

Maybe this will be useful to someone. Here’s my solution.

single-mec-events.php:

<?php
/** no direct access **/
defined('MECEXEC') or die();
?>

<?php get_header(); ?>

<?php

$single = new MEC_skin_single();


$single_event_main = $single->get_event_mec(get_the_ID());
$single_event_obj = $single_event_main[0];
$title = $single_event_obj->data->title;
$thumbnail = $single_event_obj->data->thumbnails['full'];
$content = $single_event_obj->data->content;

// Function to return event data

function get_mec_event_data($key) {
    $start_date = get_post_meta(get_the_ID(), 'mec_start_date', true);
    $start_hours = get_post_meta(get_the_ID(), 'mec_start_time_hour', true);
    $start_minutes = get_post_meta(get_the_ID(), 'mec_start_time_minutes', true);
    $start_ampm = get_post_meta(get_the_ID(), 'mec_start_time_ampm', true);
    $end_date = get_post_meta(get_the_ID(), 'mec_end_date', true);
    $end_hours = get_post_meta(get_the_ID(), 'mec_end_time_hour', true);
    $end_minutes = get_post_meta(get_the_ID(), 'mec_end_time_minutes', true);
    $end_ampm = get_post_meta(get_the_ID(), 'mec_end_time_ampm', true);
    $more_info = get_post_meta(get_the_ID(), 'mec_more_info', true);
    $cost = get_post_meta(get_the_ID(), 'mec_cost', true);
    $mec_date = get_post_meta(get_the_ID(), 'mec_date', true);
    $mec_start_datetime = get_post_meta(get_the_ID(), 'mec_start_datetime', true);

    $start_time = format_time($start_hours, $start_minutes, $start_ampm);
    $end_time = format_time($end_hours, $end_minutes, $end_ampm);


    switch ($key) {
        case 'start_date':
            return $start_date;
        case 'start_time':
            return $start_time;
        case 'end_time':
            return $end_time;
        case 'more_info':
            return $more_info;
        case 'cost':
            return $cost;
        case 'mec_date':
            return $mec_date;
        case 'mec_start_datetime':
            return $mec_start_datetime;            
        case 'start_ampm':
            return $start_ampm;        
        case 'end_ampm':
            return $end_ampm;        
        default:
            return '';
    }
}


// 24 hour conversion

function format_time($hours, $minutes, $ampm) {
    $hours = intval($hours);
    $minutes = intval($minutes);

    if ($ampm === 'PM') {
        $hours += 12;
    }

    $hours = str_pad($hours, 2, '0', STR_PAD_LEFT);
    $minutes = str_pad($minutes, 2, '0', STR_PAD_LEFT);

    return $hours . ':' . $minutes;
}


echo do_shortcode('[bricks_template id="1363"]');
?>

<?php get_footer(); ?>

Then I can get the correct info in my Bricks template by fx:

Title: {post_title}
Photo: {featured_image}
Content text: {post_content}

Date: {echo:get_mec_event_data(‘start_date’)}
Time: {echo:get_mec_event_data(‘start_time’)} - {echo:get_mec_event_data(‘end_time’)}
Link: {echo:get_mec_event_data(‘more_info’)}
Cost: {echo:get_mec_event_data(‘cost’)}

Another question though is how to get the actual date of recurring events to display, rather than the first date of the series.

Sorry @panomitrius , I abandoned the idea of using a specific template for events.
It’s complicated to keep the right information after MEC updates…

:smiling_face_with_tear:

1 Like