In WordPress woocommerce site I have custom post_type klaviyo_shop_cart
= =1137717 number of post which I don't need them so I decided to delete them from my database. to do this I have tried few plugin but due to limitation I failed to delete them.
My PHP method which can only handle 3000 post deletion i cannot increase these number. if i increase it shows 500 error.
<?php
$number = 3000 ;
$mycustomposts = get_posts(
array(
'post_type' => 'klaviyo_shop_cart',
'numberposts' => $number
)
);
foreach( $mycustomposts as $mypost ) {
// Delete's each post.
wp_delete_post( $mypost->ID, true);
// Set to False if you want to send them to Trash.
}
echo '<h3 style=:"color:red;"> DELETED!</h3>' . $number ;
?>
its very slower it an delete 3000 post at a time. SO I want to try bellow sql query to delete post. I know that I cannot delete 1137717
number of post at time so I need a better solution. my question is there any way to delete 50000
in a single query ?
DELETE FROM wp_posts WHERE post_type='klaviyo_shop_cart';
DELETE FROM wp_postmeta WHERE post_id NOT IN (SELECT id FROM wp_posts);
DELETE FROM wp_term_relationships WHERE object_id NOT IN (SELECT id FROM wp_posts);
I found this from here
this huge number of post can delete a batch operation on 50000 post delete at once.