# Purge Related Pages From LiteSpeed Cache on Update

> When a post changes, also purges the homepage and the post's category and tag archives from LiteSpeed Cache, so lists and teasers are never out of date.

- Type: PHP
- Runs: Run everywhere
- Category: [Plugin Integrations](https://wpide.com/library/category/integrations/)
- Tags: litespeed, cache, purge
- Author: WPIDE Team
- Installs: 0
- Updated: 2026-10-28
- Page: https://wpide.com/library/litespeed-purge-related-pages/

## Code

```php
add_action( 'transition_post_status', function ( $new, $old, $post ) {
    if ( ! defined( 'LSCWP_V' ) || ( 'publish' !== $new && 'publish' !== $old ) || wp_is_post_revision( $post ) || ! is_post_type_viewable( $post->post_type ) ) {
        return;
    }

    do_action( 'litespeed_purge_url', home_url( '/' ) );

    foreach ( get_object_taxonomies( $post->post_type ) as $taxonomy ) {
        if ( ! is_taxonomy_viewable( $taxonomy ) ) {
            continue;
        }
        foreach ( (array) wp_get_post_terms( $post->ID, $taxonomy ) as $term ) {
            $link = get_term_link( $term );
            if ( ! is_wp_error( $link ) ) {
                do_action( 'litespeed_purge_url', $link );
            }
        }
    }
}, 20, 3 );
```

## Notes

Uses LiteSpeed Cache's documented purge actions and does nothing if the plugin is inactive.

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "Purge Related Pages From LiteSpeed Cache on Update" in its snippet library and add it in one click; or create a new PHP snippet in WPIDE (or any code snippets plugin) and paste the code above. More snippets: https://wpide.com/library/
