delete_transient()
Delete a transient.
Hooks from the function
Return
true|false
. True if the transient was deleted, false otherwise.
Usage
delete_transient( $transient );
- $transient(string) (required)
- Transient name. Expected to not be SQL-escaped.
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. |