简体   繁体   English

使用W3 Total Cache在帖子上刷新类别

[英]Flush category on post with W3 Total Cache

I have W3 Total Cache installed and working, except that it does not correctly flush my category pages on posting or updating a post. 我已经安装并可以使用W3 Total Cache,但它在发布或更新帖子时无法正确刷新我的类别页面。 I would like to do this automatically. 我想自动执行此操作。

Within my Wordpress theme I have several category pages and they are titled category-green-widgets, category-blue-widgets etc. 在我的Wordpress主题中,我有几个类别页面,它们的标题分别为:类别绿色小部件,类别蓝色小部件等。

Some, eg category-widgets, can pull in category-red-widgets AND category-blue-widgets (I coded it this way). 有些,例如类别小工具,可以引入类别红色小工具和类别蓝色小工具(我以这种方式编码)。 I need to dump all of the categories because of this, not just the ones the post belongs to. 因此,我需要丢弃所有类别,而不仅仅是帖子所属的类别。

As a start, I'm thinking this code might work to get the post's categories: 首先,我在想这段代码可能有助于了解帖子的类别:

  /* Flush category pages */
    function category_cache_flush_on_post( $post_id ) {
        if(function_exists('w3tc_pgcache_flush_post')){
                $post_categories = wp_get_post_categories( $post_id );
                foreach($post_categories as $c)
            w3tc_pgcache_flush_post($c[0]);
        }

    }
    add_filter( 'save_post', 'category_cache_flush_on_post', 10, 1 );

So how do I dump the cache for ALL of the categories on updating or posting? 那么,如何在更新或发布时转储所有类别的缓存? What is the W3TC call for that? W3TC对此有何要求?

在页面缓存设置标签上,确保选中了“发布术语页面”选项。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM