delete_transient()WP 2.8.0

Delete a transient.

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

0

#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.

delete_transient() code WP 6.6.2

function delete_transient( $transient ) {

	/**
	 * Fires immediately before a specific transient is deleted.
	 *
	 * The dynamic portion of the hook name, `$transient`, refers to the transient name.
	 *
	 * @since 3.0.0
	 *
	 * @param string $transient Transient name.
	 */
	do_action( "delete_transient_{$transient}", $transient );

	if ( wp_using_ext_object_cache() || wp_installing() ) {
		$result = wp_cache_delete( $transient, 'transient' );
	} else {
		$option_timeout = '_transient_timeout_' . $transient;
		$option         = '_transient_' . $transient;
		$result         = delete_option( $option );

		if ( $result ) {
			delete_option( $option_timeout );
		}
	}

	if ( $result ) {

		/**
		 * Fires after a transient is deleted.
		 *
		 * @since 3.0.0
		 *
		 * @param string $transient Deleted transient name.
		 */
		do_action( 'deleted_transient', $transient );
	}

	return $result;
}