How to delete a transient on post/page publish?

I am considering it for publication of a new post.

Add the below code in your active theme’s functions.php file.

function wpse_delete_query_transient( $post ) {
    // Deletes the transient when a new post is published
    delete_transient( 'd_results' );
}
add_action( 'new_to_publish', 'wpse_delete_query_transient' );

This will delete the transient every time a new post is published.

if you want to delete the transients on differrent post status transitions, you may like to look into the codex

Leave a Comment