Start a new topic

Next upcoming event date for Countdown widget

Currently the countdown widget seems to be limited to a hardcoded date ("End time"). I would like to use the date for the next upcoming event (and also its title in a text widget like Cusotm Heading). The only option is now to manually change the date in the page which makes it not really useful.


1 person likes this idea

This feature would be great. Not every agency has time to update it every time. Hope to hear soon!

I set up a cronjob for this:


<?php

require($_SERVER['DOCUMENT_ROOT'].'/wp-load.php');

 

$post_id = xx; // ID of the post/page where the countdown is integrated

 

$args = array(

    'post_type'=> 'event',

    'order' => 'ASC',

 'orderby' => 'date',

    );

 

$the_query = new WP_Query( $args );

 

$time = substr($the_query->posts[0]->post_date, 0, -3);

if ($time!="")

{

 $content = get_post($post_id)->post_content;

 $new_content = preg_replace('/end_time="[0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}"/', 'end_time="'.$time.'"', $content);

 $events = array(

    'ID' => $post_id,

    'post_content' => $new_content,

   );

 wp_update_post( $events );

 

 echo "Update ok!";

}


Hi Webfish,
Could you please let me know how your got that running in Wordpress? I have no idea how to set up a cronjob with PHP included...
Thanks!!

 

Login or Signup to post a comment