Table Of Content
If your WordPress site is running slow due to the _transient_ptk_patterns
autoload, then this message is for you. The said transient relates to WooCommerce, and it stores information regarding the WooCommerce Pattern Toolkit API. This transient can inflate up to 500KB or more since it caches lots of patterns together with their default images that load on every request made on your site. It makes quite a difference to site performance when autoload value is set as “yes” in the database.
The issue usually happens over and over after every update of WooCommerce, so it becomes cyclical regarding performance. By disabling this autoload, you will minimize memory consumption and take your site to load at a higher pace. How you could turn off this autoloaded data is described below.
SQL Method
You can manually disable the autoload by running a SQL query on your WordPress database:
SELECT *
FROM wp_options
WHERE option_name = '_transient_ptk_patterns';
UPDATE `wp_options`
SET autoload = 'off'
WHERE option_name = '_transient_ptk_patterns';
This query changes the value of autoload to “off,” which prevents transient from loading on every page. Always backup your database in case something goes wrong.
Plugin Method
If you prefer a plugin solution, you can use an autoload optimization plugin such as “Advanced Database Cleaner“. This utility, from its options tab, will enable you to globally disable or even remove unnecessary autoloaded options by using an interface. It’s a convenient way of doing this, if you are not comfortable with directly playing around with your database.
PHP Function Method
For the developers, another approach to disable this transient is by custom code additions to your theme’s functions.php or using WPCode Snippets:
function set_transient_autoload_off() {
global $wpdb;
// Prepare the SQL query
$sql = $wpdb->prepare(
"UPDATE `$wpdb->options` SET autoload = %s WHERE option_name = %s",
'no',
'_transient_ptk_patterns'
);
// Execute the query
$result = $wpdb->query( $sql );
if ( false === $result ) {
// Handle error
echo 'Error updating autoload value.';
} else {
// Success
echo 'Autoload value updated successfully.';
}
}
This will ensure that the transient gets deleted and doesn’t reappear with each WooCommerce update. It is more automated without running SQL commands after each update.
To avoid the issue re-occuring after your update WooCommerce, you can hook it to the daily schedule using the snippet below:
// Schedule the event if it's not already scheduled
function schedule_set_transient_autoload_off() {
if ( ! wp_next_scheduled( 'set_transient_autoload_off_event' ) ) {
wp_schedule_event( time(), 'daily', 'set_transient_autoload_off_event' );
}
}
add_action( 'wp', 'schedule_set_transient_autoload_off' );
// Hook the function to the scheduled event
add_action( 'set_transient_autoload_off_event', 'set_transient_autoload_off' );
function set_transient_autoload_off() {
global $wpdb;
// Prepare the SQL query
$sql = $wpdb->prepare(
"UPDATE `$wpdb->options` SET autoload = %s WHERE option_name = %s",
'no',
'_transient_ptk_patterns'
);
// Execute the query
$result = $wpdb->query( $sql );
if ( false === $result ) {
// Handle error
error_log( 'Error updating autoload value.' );
} else {
// Success
error_log( 'Autoload value updated successfully.' );
}
}
It should improve your site performance. Testing showed that once disabled, the site speeds improved, with no negative effects on the user experience. Disabling this transient will prevent your site from loading unnecessary data, which should amply speed up how fast pages load and make a more responsive user experience. You’ll even gain points on pagespeed.web.dev.