-
Notifications
You must be signed in to change notification settings - Fork 17
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: clean the cache of a specific page for custom post types #257
Comments
@benoitchantre I'm not clear on what you're asking for here. Are you wanting an option to purge all cache files for a specific Custom Post Type? You say that you want to "clean the cache for a specific page related to custom post types", but what would 'related' mean here? How is the page related to the custom post types and how would Quick Cache know that the page is related? |
Same here. Sounds like an interesting idea, but some more detail would be really helpful. Just a few more specifics (i.e. answers to Raam's questions) to help clarify the intent. |
The context The issue The solution |
@benoitchantre Thank you very much for the additional information. That was very helpful! I see now what you're trying to do. First, I'd like to point you to a similar GitHub issue where someone was looking for a way to purge the cache for a specific page whenever a specific Custom Post Type was saved. I provided example code that you can use to achieve this: See issue #73. Regarding your feature request: There's another feature request open for creating a place to specify user-defined URIs to purge with post cache (#111). It sounds like if that feature request was implemented, you'd be able to simply specify the URI to your page (e.g., Of course that wouldn't be quite a granular as it could be (i.e., if you saved a non-Custom Post Type, it would still clear your Custom Post Type archive page), but it sounds like that might still be better than requiring custom code to be implemented. What do you think? Would a place to specify URIs to purge whenever the post cache is cleared (i.e., whenever a post is saved) work for you? |
@raamdev Thanks for your detailed answer. I can edit my theme with the solution you provided in issue #73, because I use a custom theme. If this was a premium theme, I would have to make a child theme to keep that behavior after an update of the theme. I think it is a better solution to have a setting in quick cache to define which cache should be cleared when a custom post is saved. It avoids to edit the theme and keeps everything centralized in quick cache. The feature request #111 would work for me. It would be a lot better than to erase the cache of the whole website. For a website with a lot of visits and a lot of posts published regulary, it would be better to have a more granular solution, but that is not my case. |
@benoitchantre Thank you. I will close this feature request for now and instead focus on getting #73 completed. If I see demand for a more granular solution than #73, I will reopen this. :) |
No problem. Thanks for the support!
|
@raamdev I have tested the solution described in #73, but that doesn't work for me. Maybe I have missed something. I want to purge the cache the page ID /**
* Clear the cache for the animal page
*/
add_action( 'clear_cache_for_animal_page', 'save_post_ts_animal', 10, 1 );
function clear_cache_for_animal_page( ) {
$GLOBALS['quick_cache']->auto_purge_post_cache(10);
} Is it because the name of my custom post type contains an underscore? |
I'm not sure I understand that statement. What's the difference between the 'post' and the 'page' in this case? In WordPress (in the code) a Post and a Page are essentially the same thing and they all have an ID. So you couldn't have a Post with ID Are you referring to an archive view for a Custom Post Type? For example, assuming the post type name is Are you trying to clear the Archive View for |
I use a custom page template to display my custom post types ts_animal. It offers me more flexibility in the blackend than an archive page. The custom post type ts_animal is a post about an animal: a definition. When I save a custom post, the function should clear the cache of the page (ID = 10), but this doesn't happen. I hope my explanation is better than before.
|
On this line: add_action( 'clear_cache_for_animal_page', 'save_post_ts_animal', 10, 1 ); Try changing |
I have changed |
@benoitchantre I just wanted to point out a problem in this code snippet... /**
* Clear the cache for the animal page
*/
add_action( 'clear_cache_for_animal_page', 'save_post_ts_animal', 10, 1 );
function clear_cache_for_animal_page( ) {
$GLOBALS['quick_cache']->auto_purge_post_cache(10);
} add_action( 'clear_cache_for_animal_page', 'save_post_ts_animal', 10, 1 ); Should be... add_action( 'save_post_ts_animal', 'clear_cache_for_animal_page', 10, 1 ); See also: http://codex.wordpress.org/Function_Reference/add_action
Where |
@jaswsinc thanks for your comment. It was a basic error... Now everything work :-) |
@benoitchantre Sorry for the silly mistake! I'm glad to hear it's working now. :) @jaswsinc Thanks for pointing out the error! |
In the case you display custom posts in a page, you are forced to manually clean the cache for the whole site to reflect the changes.
It would be nice to have a way to automatically clean the cache for a specific page related to custom post types.
Maybe a new setting in the options or a function that we can use when
save_post
is triggered?The text was updated successfully, but these errors were encountered: