delete_transient()
Deletes a transient option.
Hooks from the function
Returns
true|false
. Boolean true or false, depending on whether the option was successfully deleted.
Usage
delete_transient( $transient );
- $transient(string) (required)
- The name of the transient option. The passed value will not be sanitized against SQL injections (the string will not be escaped with slashes).
Examples
#1 Clearing Temporary Options
Delete temporary options with the hook edit_term
:
// Add this function to the edit_term event, // which is triggered when a category or tag is edited add_action( 'edit_term', 'edit_term_delete_transient' ); // Create a simple function to remove transient option function edit_term_delete_transient() { delete_transient( 'special_query_results' ); }
This example assumes that the special_query_results transient option records the result of the SQL query and then simply retrieves it from there until we edit the tag or category. Then the query is re-saved.
Changelog
Since 2.8.0 | Introduced. |