Sorry for the delay, I’m getting over Covid.
I am actually trying to purge all custom posts that have a specific term in a custom tax when the the term changes.
Ah, that’s not terribly hard.
You want to hook into the term editor or just say “Any time a term is edited, flush the site”
The latter is ‘faster’ to code:
function my_varnish_purge_events( $actions ) {
$myactions = array(
'edit_term', // When a term is edited
);
array_merge( $actions, $myactions ) ;
return $actions;
}
add_filter( 'varnish_http_purge_events', 'my_varnish_purge_events' );
add_filter( 'varnish_http_purge_events_full', 'my_varnish_purge_events' );
The double filters are because I had to put in some odd redundancy.
The former would mean hooking into edit_term :
function my_term_edit( $term_id, $tt_id, $taxonomy ){
// do some stuff
}
add_action( 'edit_term', 'my_term_edit', 10, 3 );
And then having code that
1. Gets a list of all posts in that term
2. Add all the posts by URL to be purged
That second step is probably going to be the biggest headache. If you look at the wp-cli code for the plugin – https://github.com/Ipstenu/varnish-http-purge/blob/trunk/wp-cli.php – you’ll see there’s a __construct() to create a connection to VarnishPurger(), and that allows you to call things like:
$this->varnish_purge->purge_url( $url );
More or less that’ll be what you want to duplicate.