Skip to content

Instantly share code, notes, and snippets.

@topher1kenobe
Last active December 16, 2015 11:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save topher1kenobe/5430861 to your computer and use it in GitHub Desktop.
Save topher1kenobe/5430861 to your computer and use it in GitHub Desktop.
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