0
是否有任何方式將所有自定義帖子類型狀態從「發佈」更改爲草稿?針對自定義類型的移動帖子狀態的Wordpress批處理
場景: 在這裏,我需要運行一個腳本。 我的帖子類型是:property_listing 現在我需要製作所有文章草稿,然後執行我的自定義操作。
可能嗎?
是否有任何方式將所有自定義帖子類型狀態從「發佈」更改爲草稿?針對自定義類型的移動帖子狀態的Wordpress批處理
場景: 在這裏,我需要運行一個腳本。 我的帖子類型是:property_listing 現在我需要製作所有文章草稿,然後執行我的自定義操作。
可能嗎?
如果您有Cpanel或數據庫訪問權限,則可以在DB面板中運行此查詢。
update table wp_posts set status='draft' where post_type='property_listing'
否則,使用此代碼。(它粘貼在你的主題function.php)
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();
}
}