Skip to content

Instantly share code, notes, and snippets.

@pablo-sg-pacheco
Last active January 31, 2020 18:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pablo-sg-pacheco/9200170e5cc758252927020f958104a6 to your computer and use it in GitHub Desktop.
Save pablo-sg-pacheco/9200170e5cc758252927020f958104a6 to your computer and use it in GitHub Desktop.
Delete WordPress Transients by Prefix
<?php
/**
* Deletes transients that match a specific prefix.
*
* @author Pablo Pacheco <pablo.sg.pacheco@gmail.com>
* @param string $prefix prefix to search for.
* @return int|bool Boolean true for CREATE, ALTER, TRUNCATE and DROP queries. Number of rows affected/selected for all other queries. Boolean false on error.
*/
function delete_transients_by_prefix($prefix){
global $wpdb;
$sql = "delete from wp_options where option_name REGEXP %s";
return $wpdb->query( $wpdb->prepare( $sql, '^_transient_' . $prefix ) );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment