Pergunta

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

Foi útil?

Solução

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.

Outras dicas

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.

<?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.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a wordpress.stackexchange
scroll top