LoginSignup
1
2

More than 5 years have passed since last update.

WordPressの大量の記事で、ある月をそのままゴミ箱へ持っていく方法

Posted at

お世話になります。

WordPressの大量の記事(1000件以上)があって、ある月の分をそのままゴミ箱へ持っていく方法です。

管理画面から、対象の記事を選んで、ゴミ箱へというやりかたがありますが、
数が少なければいいです。その月で2000件以上とかあったらどうしますか?

以下のPHPスクリプトファイルを作って、一気にゴミ箱へ持って行きます。

delete.php

<?php


require dirname(__FILE__) . "/wp-load.php";

//    $month=$argv[1];
    $month="201504";
    query_posts('posts_per_page=500&post_status=publish&m=' . $month );

    if (have_posts()) :
        while (have_posts()) : the_post();

            echo "    " .get_the_title() . '/' . get_the_ID() . "\n";
            $my_post = array(
               'ID'           => get_the_ID(),
               'post_status'   => 'trash',
            );

           wp_update_post( $my_post );

        endwhile;
    endif;

    wp_reset_query();

?>

問題がなければ別途記事化した方法
WordPressの大量の記事が、ゴミ箱にあって一気に消去(削除)する方法
で削除します。

よかったら使ってください。

1
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
2