2017-04-15 11 views
0

すべてのカスタム投稿タイプのステータスが「公開」から「ドラフト」に変更される方法はありますか?WordPressのバッチを移動タイプのために移動する

シナリオ: ここでスクリプトを実行する必要があります。 私の投稿の種類は:property_listing 今私はすべての草案を作成し、私のカスタム操作を実行する必要があります。

可能ですか?

答えて

0

Cpanelまたはデータベースにアクセスしている場合は、DBパネルでこのクエリを実行できます。

update table wp_posts set status='draft' where post_type='property_listing' 

そうでない場合は、このコードを使用しています。

add_action('init','change_mypost_status'); 
function change_mypost_status(){ 
    $args = array(
     'post_type' => 'property_listing', 
     'posts_per_page' => -1 
    ); 
    $the_query = new WP_Query($args); 
    if ($the_query->have_posts()) { 
     echo '<ul>'; 
     while ($the_query->have_posts()) { 
      $the_query->the_post(); 
      $current_post = array(
        'ID'   => get_the_ID(), 
        'post_status' => 'draft' 
      ); 
      // Update the post into the database 
       wp_update_post($current_post); 
     } 
     wp_reset_postdata(); 
    } 
} 
(あなたのテーマのfunction.phpに貼り付けます)
関連する問題