Skip Navigation

[Gelöst] Date fields from Events Manager are not interpreted as dates.

Dieser Thread wurde gelöst. Hier ist eine Beschreibung des Problems und der Lösung.

Problem:
Date fields from Events Manager are not interpreted as dates as well as display it with specific format

Solution:
To display Events Calendar date in specific format you need to add custom shortcode to your current theme's functions.php file.

You can find proposed solution, in this case, with the following reply:
=> https://toolset.com/forums/topic/date-fields-from-events-manager-are-not-interpreted-as-dates/#post-1078716

Relevant Documentation:

100% of people find this useful.

This support ticket is created vor 6 Jahren, 3 Monaten. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Heute stehen keine Supporter zur Arbeit im Werkzeugsatz-Forum zur Verfügung. Sie können gern Tickets erstellen, die wir bearbeiten werden, sobald wir online sind. Vielen Dank für Ihr Verständnis.

Sun Mon Tue Wed Thu Fri Sat
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Kolkata (GMT+05:30)

Dieses Thema enthält 12 Antworten, hat 2 Stimmen.

Zuletzt aktualisiert von tammot vor 6 Jahren, 3 Monaten.

Assistiert von: Minesh.

Author
Artikel
#1078525
Need to create a schedule   calendar   Toolset.png

* Tell us what you are trying to do?

I am trying to develop a view that holds all events (as from today and further in the future, only events that belong to a certain category), using the fields that are available in the Events Manager (versteckter Link where I am using the Pro version):

-- _event_start
-- _event_end
It seems that these fields are not interpreted as datetime fields (although in my PHPMyAdmin shows that they are datetime fields )

* Is there any documentation that you are following?

I have visited:
-- https://toolset.com/forums/topic/order-by-is-not-working-when-using-custom-field/
-- https://toolset.com/forums/topic/need-to-create-a-schedule-calendar/

At first I tried as code in the view:
<h3>[wpv-post-title]</h3>
<p>[wpv-post-field name='_event_start' format="l F j, Y"]</p>

This resulted in the following output on the screen:

Title of event
2018-07-04

In the second link above I then used the code in Reply #365125, but this did not work. I suspected that the code is not correct, see attachment. I rewrote the code to:

function date_format($atts){
$format = $atts["format"];
$date = $atts["date"];

return date($format, $date);
}
add_shortcode("date-format", "date_format");

and I added:
[date-format date="[wpv-post-field name='_event_end_date']" format="F j, Y"] to my view, but this gave me:

Fatal error: Cannot redeclare date_format() in V:\power\wp-content\themes\understrap-child\functions.php on line 194

Line 194 says: }

--------------------------------------
Futhermore: I also wanted to filter on the date and show only events that take place today and in the futute, but filtering did not work either.

I really would like your advice on this.

Please visit versteckter Link to see what happens when I use

<h3>[wpv-post-title]</h3>
<p>[wpv-post-field name='_event_start' format="l F j, Y"]</p>
<p>[wpv-post-field name='_event_end' format="l F j, Y"]</p>
<p>[date-format date="[wpv-post-field name='_event_end']" format="F j, Y"]</p>

Of course for the example I left away the incorrect code in functions.php

Thanking you in advance,

Tammo ter Hark

#1078537
Need to create a schedule   calendar   Toolset.png

I now see that I made an error in the support question:
After I added the code:

function date_format($atts){
$format = $atts["format"];
$date = $atts["date"];

return date($format, $date);
}
add_shortcode("date-format", "date_format");

to functions.php I added:

[date-format date="[wpv-post-field name='_event_end']" format="F j, Y"]

to my view, but this gave me:

Fatal error: Cannot redeclare date_format() in V:\power\wp-content\themes\understrap-child\functions.php on line 194

Line 194 says:

}

This corresponds with line 6 in the above code.

#1078616

Minesh
Supporter

Sprachen: Englisch (English )

Zeitzone: Asia/Kolkata (GMT+05:30)

Hello. Thank you for contacting the Toolset support.

Well - could you please try to add the function as given under and try to resolve your issue:

function func_date_format($atts){
$format = $atts["format"];
$date = $atts["date"];
 
return date($format, $date);
}
add_shortcode("date-format", "func_date_format");
#1078653

Hi Minesh,

thanks for the swift reply. What you suggested did make a difference, but it is not right yet.

I pasted your code into functions.php:

function func_date_format($atts){
    $format = $atts["format"];
    $date = $atts["date"];

    return date($format, $date);
}

add_shortcode("date-format", "func_date_format");

and I changed the views code to:

<h3>[wpv-post-title]</h3>
<p>[wpv-post-field name='_event_start' format="l j F Y"]</p>
<p>[wpv-post-field name='_event_end' format="l j F Y"]</p>
<p>[date-format date="[wpv-post-field name='_event_end']" format="l j F Y"]</p>

I also tried

<p>[date-format wpv-post-field name='_event_end' format="l j F Y"]</p>

on the last line, but this gave no difference.

On the fontside, this resulted in:
POWER-film ‘The Trip to Spain’
2018-07-04 12:00:00

2018-07-04 14:00:00

Thursday 1 January 1970

As you will be able to see at:
versteckter Link

So: thank you, but I still hope for your advice in perfecting this.

Tammo

#1078668

Minesh
Supporter

Sprachen: Englisch (English )

Zeitzone: Asia/Kolkata (GMT+05:30)

could you please share access details.

*** Please make a FULL BACKUP of your database and website.***
I would also eventually need to request temporary access (WP-Admin and FTP) to your site. Preferably to a test site where the problem has been replicated if possible in order to be of better help and check if some configurations might need to be changed.

I would additionally need your permission to de- and re-activate Plugins and the Theme, and to change configurations on the site. This is also a reason the backup is really important. If you agree to this, please use the form fields I have enabled below to provide temporary access details (wp-admin and FTP).

I have set the next reply to private which means only you and I have access to it.

#1078671
View Bewerken ‹ Power Amersfoort — WordPress.png

Maybe the image gives a clue?

#1078687

Minesh
Supporter

Sprachen: Englisch (English )

Zeitzone: Asia/Kolkata (GMT+05:30)

could you please share access details.

I have set the next reply to private which means only you and I have access to it.

#1078688

access details - removed

I have a good backup of the site.

#1078689

I cannot see that the above reply is private. Please set it to private.

Thank you!

#1078716

Minesh
Supporter

Sprachen: Englisch (English )

Zeitzone: Asia/Kolkata (GMT+05:30)

I've added following shortcode to your current theme's functions.php file and adjusted the code as well to display the correct date.

I also shared two different shortcodes to display both of your date in simple as well as in dutch text as well.

/* for simple date */ 
function func_date_format($atts){
    $format = $atts["format"];
    $date = $atts["date"];
	return date($format, strtotime($date));
}
add_shortcode("date-format", "func_date_format");

/* to display date with dutch language */
function func_date_format_in_dutch($atts){
    $format = $atts["format"];
    $date = $atts["date"];
	setlocale(LC_TIME, "de_DE");
    return strftime("%A %e %B %Y",strtotime($date));
    
}
add_shortcode("date-format-in-dutch", "func_date_format_in_dutch");

Additionally the <strog> format attribute with shortcode [wpv-post-field] is NOT supported so I removed it and your view's code looks like as given under:

<h3>[wpv-post-title]</h3>
<p>[wpv-post-field name='_event_start']</p>
<p>[wpv-post-field name='_event_end']</p>
<p>Simple Date: [date-format date="[wpv-post-field name='_event_end']" format="l j F Y"]</p>
<p>In Dutch: [date-format-in-dutch  date="[wpv-post-field name='_event_end']" format="l j F Y"]</p>

Could you please confirm it works at your end as well: versteckter Link

Please let me know your feedaback 🙂

#1078740

Thank you, this was the right solution.

Just a small thing (which I can solve easily myself): Dutch is the language in the Netherlands, so the language code is nl-NL. de_DE is for German. But I know this is sometimes confusing for people outside Europe..

#1081144

Just to make this entry more complete:

I saw on my local installation (Xampp on Windows) that this solution does not work, due to a different way of working with locale.

Changing the code in function.php to

function func_date_format_NL($atts){
    $format = $atts["format"];
    $date = $atts["date"];
	  setlocale(LC_ALL, 'NL-nl');
    return strftime("%A %#d %B %Y %H:%M",strtotime($date));  
}

made it work both on Windows as well as on Linux (live server). Notice the substitution of %e by %#d.

Documented here:
versteckter Link

#1083021

Thank you very much! This was of great help!

Tammo