Last active
December 16, 2015 11:58
-
-
Save topher1kenobe/5430861 to your computer and use it in GitHub Desktop.
Delete WordPress transient under the proper conditions
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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