delete_transient( string $transient )

Delete a transient.


Description Description


Parameters Parameters

$transient

(string) (Required) Transient name. Expected to not be SQL-escaped.


Top ↑

Return Return

(bool) true if successful, false otherwise


Top ↑

Source Source

File: wp-includes/option.php

619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
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() ) {
        $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;
}

Top ↑

Changelog Changelog

Changelog
Version Description
2.8.0 Introduced.


Top ↑

User Contributed Notes User Contributed Notes

  1. Skip to note 1 content
    Contributed by Codex

    Clearing our transient via the edit_term hook

    1
    2
    3
    4
    5
    6
    // Create a simple function to delete our transient
    function wpdocs_edit_term_delete_transient() {
         delete_transient( 'special_query_results' );
    }
    // Add the function to the edit_term hook so it runs when categories/tags are edited
    add_action( 'edit_term', 'wpdocs_edit_term_delete_transient' );

You must log in before being able to contribute a note or feedback.