Last active
January 31, 2020 18:10
-
-
Save pablo-sg-pacheco/9200170e5cc758252927020f958104a6 to your computer and use it in GitHub Desktop.
Delete WordPress Transients by Prefix
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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