Posted on

Weather Atlas Widget not updating issue solved

I had a client who needed to display today’s weather on a big display in many hotels he manages.

My solution was simply creating a WordPress website that displays today’s weather with the specific hotel related gallery and information.

The WordPress site hosts a page per location of each hotel and displays the Weather Atlas Widget using a shortcode dedicated for each location of the hotel.

The problem I discovered is that the one embedded on the homepage was updating properly, but not the other ones.

This was on a vanilla install of WordPress without any caching plugin. Deleting the browser cache did not help as well.

I tried deleting all the expired WordPress transient for the Weather Atlas plugin, but it did not solve the issue until I deleted all the transient files from the plugin whether it was expired or not.

So, the solution I developed is to delete all the transient from the plugin on an hourly basis using the wp_cron as it shows in the following code:

if( !wp_get_schedule( 'webspi_weather_atlas_transient_cleaner' ) ){
	wp_schedule_event( time(), 'hourly', 'webspi_weather_atlas_transient_cleaner');
	add_action( 'webspi_weather_atlas_transient_cleaner', 'webspi_clean_weather_atlas_transient' );
function webspi_clean_weather_atlas_transient(){
	global $wpdb;
	$sql = "SELECT *
            FROM  $wpdb->options
            WHERE option_name LIKE '%\_transient\_weather\_atlas\_%'
            ORDER BY option_name";
	$transients = $wpdb->get_results( $sql );

	foreach( $transients as $index => $trans ){
		$trans_name = $trans->option_name;
		if( strpos( $trans_name, 'weather_atlas_transient' ) !== false ){
			$trans_name = preg_replace('/^_transient_/', '', $trans_name);
			$deleted = delete_transient( $trans_name );
			if( $deleted ){
				error_log( $trans_name . ' deleted' );
			} else {
				error_log( $trans_name . ' could not be deleted' );

Above code is provided for your reference only without any warranty or legal responsibility.

Because I don’t want this customization to get overriden by the plugin update, simply dropped it in my child theme functions.php file and it is working fine.