douhuiqi3855 2018-07-27 18:45
浏览 75

如何从WordPress数据库中删除大量帖子

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.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥50 导入文件到网吧的电脑并且在重启之后不会被恢复
    • ¥15 (希望可以解决问题)ma和mb文件无法正常打开,打开后是空白,但是有正常内存占用,但可以在打开Maya应用程序后打开场景ma和mb格式。
    • ¥20 ML307A在使用AT命令连接EMQX平台的MQTT时被拒绝
    • ¥20 腾讯企业邮箱邮件可以恢复么
    • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?
    • ¥15 错误 LNK2001 无法解析的外部符号
    • ¥50 安装pyaudiokits失败
    • ¥15 计组这些题应该咋做呀
    • ¥60 更换迈创SOL6M4AE卡的时候,驱动要重新装才能使用,怎么解决?
    • ¥15 让node服务器有自动加载文件的功能