将文件保存到插件目录中,然后从管理面板激活插件。激活后,将查询所有WooCommerce产品post_status
trash
并用状态更新它们publish
.
Please test the plugin first in your end, and then apply to the live site.
<?php
/**
* Plugin Name: WooCommerce Trash Recovery
* Plugin URI: http://wordpress.stackexchange.com/q/218859/22728
*/
/**
* Trash retrival for WooCommerce
* @return void
*/
function wpse218859_trash_to_publish_on_activation() {
$prod_query = new WP_Query(
array(
\'post_type\' => \'product\',
\'post_status\' => \'trash\',
\'posts_per_page\' => -1
)
);
while( $prod_query->have_posts() ) : $prod_query->the_post();
wp_update_post(array(
\'ID\' => get_the_ID(),
\'post_status\' => \'publish\'
));
endwhile;
wp_reset_postdata();
}
register_activation_hook( __FILE__, \'wpse218859_trash_to_publish_on_activation\' );
Deactivate and delete it, after completion.