Do these pages contain the Complianz shortcode? Or if you’re using Gutenberg, do they contain the Complianz Gutenberg block?
If so, the code below will remove all pages with the UK cookie policy shortcode. If not, I can make you a function that looks at the title, let me know. You can add the code in your theme’s functions.php and remove it after it has run (a page refresh).
function cmplz_cleanup(){
$type = 'cookie-statement-uk';
$shortcode = 'cmplz-document';
$args = array(
'number' => '200',
);
$pages = get_pages($args); foreach ($pages as $page) {
$post_meta = get_post_meta($page->ID, 'cmplz_shortcode',true);
if ($post_meta) {
$html = $post_meta;
} else {
$html = $page->post_content;
}
delete_transient('cmplz_shortcode_' . $type);
/*
* Gutenberg block check
*
* */
//check if block contains property
if (preg_match('/"selectedDocument":"(.*?)"/i', $html, $matches)) {
if ($matches[1]===$type) {
wp_delete_post( $page->ID, true);
continue;
}
}
/*
* If nothing found, or if not Gutenberg, check for shortcodes.
* Classic shortcode check
*
* */
if (has_shortcode($html, $shortcode) && strpos($html, 'type="' . $type.'"')!==FALSE) {
wp_delete_post( $page->ID, true);
}
}
}
add_action('admin_init', 'cmplz_cleanup');