hello i have an ecommerce with Wordpress + Woocommerce, just yesterday a hacker boy or...i don't know moved all woocommerce products in to the trash.... there are lots of products and default wordpress bulk edit didn't work propelly,

so i think make a custom slq query for edit wp_posts table and post_status from trash to publish, how i can do it, any help please?

Thank you all in advance

2 Answers 2


I am not good at SQL but I believe this SQL query will do the job for you.

UPDATE wp_posts 
SET post_status = 'publish' 
WHERE post_type = 'product' AND post_status = 'trash';

Please remember to change WP database prefix if it is not default wp.

  • work great thank you! But after all products restored no category assigned in front end, categories assigned ony i back-end.... how i can fix it?
    – Stew
    Feb 25, 2016 at 15:32
  • fix after permalinks saved
    – Stew
    Feb 25, 2016 at 15:42

Save the file into your Plugin directory, and from admin panel, activate the plugin. On activation this will query for all the WooCommerce products with post_status trash and update them with status publish.

Please test the plugin first in your end, and then apply to the live site.

 * 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(
                    'post_type'         => 'product',
                    'post_status'       => 'trash',
                    'posts_per_page'    => -1

    while( $prod_query->have_posts() ) : $prod_query->the_post();

            'ID'            =>  get_the_ID(),
            'post_status'   =>  'publish'

register_activation_hook( __FILE__, 'wpse218859_trash_to_publish_on_activation' );

Deactivate and delete it, after completion.

  • error when try install PCLZIP_ERR_BAD_FORMAT (-10) : Unable to find End of Central Dir Record signature
    – Stew
    Feb 25, 2016 at 15:07
  • You put the code into a file, i.e. named wc-trash-recovery.php, and then put the file in /wp-content/plugins directory, and then from WordPress admin panel > Plugins, you activated WooCommerce Trash Recovery. If is that your way, I'm afraid, I can't save you any more. Because it's the way of activating a sole plugin. Feb 25, 2016 at 16:13
  • anyway thank you, sure your plugin work great, i wrong named it, i called it trash.php, reason for the error in installation
    – Stew
    Feb 25, 2016 at 16:35
  • trash.php as a plugin file name can never cause an error like this. seems weird! Feb 25, 2016 at 19:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.