Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature request: Purge page when custom post type is updated / added #73

Closed
phwconz opened this issue Feb 17, 2014 · 2 comments
Closed

Comments

@phwconz
Copy link

phwconz commented Feb 17, 2014

I often use custom post types and output them to a page. Would be great to be able to purge that page when a custom post is updated / added, i.e.: identical to the way the index page is purged when a new default post is created / updated.

@raamdev
Copy link
Contributor

raamdev commented Feb 26, 2014

Using the save_post_{$post_type} hook, which is fired whenever that custom post type is created or updated (see docs), you can add something like the following to your theme's functions.php file, or to a MU-Plugin, to clear the cache for a given page whenever a post with that custom post type is saved:

add_action( 'clear_cache_for_page_id_5', 'save_post_my-custom-post-type', 10, 1 );

function clear_cache_for_page_id_5( ) {
    $GLOBALS['quick_cache']->auto_purge_post_cache(5);
}

You'll want to change 5 to the ID of the Page/Post whose cache you'd like to clear when that custom post type is saved, and you'll want to change my-custom-post-type to the actual name of your Custom Post Type.

@raamdev raamdev closed this as completed Feb 26, 2014
@phwconz
Copy link
Author

phwconz commented Mar 4, 2014

Awesome, thanks for the advice.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants