Create a gist now

Instantly share code, notes, and snippets.

Delete WordPress transient under the proper conditions
// delete featured coaches transient on coach save
function delete_featured_transient($post_id) {
// First we want to make sure that this is a real save, not simply an auto save
if ( !wp_is_post_revision( $post_id ) ) {
// now we declare our custom content type, because we only want to run this
// on the save of this type
$slug = 'coaches';
// this is where we actually make sure we're on the right type.
$_POST += array("{$slug}_edit_nonce" => '');
if ( $slug != $_POST['post_type'] ) {
return;
}
// assuming we're on the proper type, set the transient name
$transient_name = 'featured_coaches';
// now delete the actual transient
delete_transient($transient_name);
}
// end delete_featured_transient
}
// now we hook that function into save_post and it's all set
add_action('save_post','delete_featured_transient');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment