Format “Now”
-
Hi,
Can I set the “Now” format for ongoing events?
-
Hi @matthew99,
If by “ongoing events” you mean my EM add-on “EM – Ongoing Events”, please redirect your question to the correct forum. 😉If you mean showing/altering the time of an event that is currently taking place? EM does not have a “Happening now” option. You could try and achieve that by creating a custom placeholder, checking the timespan. EM only checks the date and includes today either yes/no. (Setting: “Are current events past?”)
Yes, I meant showing/altering the time of an event that is currently taking place.
Thank you for your answer 😉I was bored tonight, so I created this for you 😉
function em_placeholder_happening_now($replacement, $EM_Event, $placeholder) { if($placeholder === "#_HAPPENINGNOW") { // Fetch the complete start & end timestamps (Y-m-d H:i:s) and convert them to an integer for comparison. $start = strtotime(get_post_meta($EM_Event->post_id, '_event_start', true)); $end = strtotime(get_post_meta($EM_Event->post_id, '_event_end', true)); $now = strtotime('now'); // Check if the current time is after the start and before the end of this event. if( ($now > $start) && ($now < $end) ) { $replacement = "Happening now!"; } else { $replacement = $EM_Event->output("#_EVENTDATES"); } } return $replacement; } add_filter('em_event_output_placeholder', 'em_placeholder_happening_now', 10, 3);Fantastic! I haven’t been here for a long time.
Thank you @duisterdenhaag 😉-
This reply was modified 6 years, 3 months ago by
matthew99.
I have tried many files (I watched the tutorial) but the script does’t work.
I have tried many files
What files?
Just paste in your theme’s functions.php or simply use https://ww.wp.xz.cn/plugins/code-snippets/
I did everything again and it works. Thank you 🙂
-
This reply was modified 6 years, 3 months ago by
The topic ‘Format “Now”’ is closed to new replies.