Note: This is now included in Timeline Express Pro, so the code below is not needed when using the Pro version. If you are experiencing issues with qtranslate and Timeline Express Pro, reach out to our support team.

Some of our users have reported that the qTranslate plugin is not loading the saved translations on the front end of the site when a user changes the site language. This was originally reported to us on the WordPress.org support forums here: https://wordpress.org/support/topic/issue-with-qtranslate-plugin-2/.

After some thorough testing, we have tracked down the issue directly related to the built-in caching mechanism built into Timeline Express. In short, we have caching built into the timelines to prevent an excessive number of queries being run on each page load, or any heavy MySQL queries running multiple times.

The issue arises when a user tries to switch the site language, but English (or the default language) is stored in the site’s cache. The page refreshes and the cached default translations are re-loaded. Fortunately, this is a very simple fix using some of the helper functions packaged with Timeline Express.

Solution

The quickest, and easiest, solution to resolving this minor issue with qTranslate is to drop the following code inside of your themes functions.php file. This bit of code is going to bust the Timeline Express cache on pages where a Timeline is being used and qTranslate loads additional translations.

This is the best solution in that it first checks if the shortcode is being used and then it checks if the page contains any Timeline Express cache, before clearing it.


/**
 * Clear Timeline Express cache on qtranslate pages
 *
 * @author Code Parrots 
 */
function timeline_qtranslate_bust_cache() {

	global $post;

	if ( ! isset( $post->ID ) || false === get_transient( "timeline-express-query-{$post->ID}" ) ) {

		return;

	}

	delete_transient( "timeline-express-query-{$post->ID}" );

}
add_action( 'qtranslate_head_add_css', 'timeline_qtranslate_bust_cache' );