Get dynamic start date of an event

[ad_1]

Hi! Yes, you’ll likely need to use a custom shortcode to format it the way you want, something like this:

/**
 * Get Event Start Date in Custom Format
 * 
 * Custom shortcode for Contact Form 7 - Dynamic Text Extension
 *
 * @see https://projectdmc.org/support/topic/get-dynamic-start-date-of-an-event/
 * @see https://www.php.net/manual/en/datetimeimmutable.createfromformat.php
 *
 * @return string The event's start time formatted as d.m.Y H:i or an empty string on failure.
 */
function jumpinsteph_event_start_date()
{
    // Call the CF7_get_custom_field function directly, returns date formatted as YYYY-MM-DD HH:mm:ss
    $start_date = wpcf7dtx_get_custom_field(array('key' => '_EventStartDate'));
    if ($start_date) {
        // Convert string to DateTime object
        $start_date = date_create_from_format('Y-m-d H:i:s', $start_date, new DateTimeZone(wp_timezone_string()));
        if ($start_date !== false) {
            // Return with desired format
            return $start_date->format('d.m.Y H:i');
        }
    }
    return ''; // Return empty string on failure
}
add_shortcode('jumpinsteph_event_start_date', 'jumpinsteph_event_start_date');

And then in your form template, simply use [dynamic_text debutformation "jumpinsteph_event_start_date"]

Let me know if that works for you!

 

This site will teach you how to build a WordPress website for beginners. We will cover everything from installing WordPress to adding pages, posts, and images to your site. You will learn how to customize your site with themes and plugins, as well as how to market your site online.

Buy WordPress Transfer