Let’s say you have a recent posts listing, and you’re storing the list of recent posts in a transient to reduce queries. This code will delete the transient when you publish a post so that it’s regenerated using more recent data next time it is requested.
<?php | |
function be_purge_recent_post_cache( $new, $old, $post ) { | |
if( 'publish' == $new ) | |
delete_transient( 'recent_posts_query_results' ); | |
} | |
add_action( âtransition_post_statusâ, âbe_purge_recent_post_cacheâ, 10, 3 ); |