0

As WordPress since version 4.6.1 or so ignores define('WP_POST_REVISIONS', false); definition (at least in my WP instance), it tries to make as much revisions as possible.

Even if a post or a WooCommerce product was opened for just CTRL+A -> CTRL+C and then closed without editing, in most cases I'll get a nice but totally unneeded revision entry in the database for that particular post.

As I don't think it is a good idea to forcibly delete anything directly in mySQL database I'd better turn revisions into post drafts or product drafts using the following not so difficult SQL query:

UPDATE `wp_posts` SET `post_date` = '2222-12-31 00:00:00' WHERE `wp_posts`.`post_type` = 'revision';
UPDATE `wp_posts` SET `post_status` = 'draft' WHERE `wp_posts`.`post_type` = 'revision';
UPDATE `wp_posts` SET `post_type` = 'post' WHERE `wp_posts`.`post_type` = 'revision';

But unfortunately both post revisions or product revisions look absolutely the same in wp_posts table comparing their post_status and post_type entries, so the product revisions turn into post drafts after applying the above query.

So my question is how could I detect WooCommerce product revisions and turn them into product drafts before doing the same for post revisions?

  • Were you able to test this solution? – yivi Jan 7 '17 at 7:22
  • Not yet. WooCommerce haven't added any revision by itself for the moment. I'll try it immediately when I have both WP and WC revisions at the same time. – YKKY Feb 5 '17 at 15:29
0

Woocommerce uses the post_type product for products, so it should be easy enough to search for those instead of posts.

Just look out for the proper post_type.

You could filter the revisions using a self-joined select like this:

SELECT *
FROM `wp_posts` p1
LEFT JOIN `wp_posts` p2 ON (p2.post_parent = p1.ID and p1.post_type = 'products')
WHERE p1.`post_type` = "revision"
LIMIT 50

Still, I wouldn't convert my revisions into posts nor anything like that. You'll end up with TONS of garbage posts laying around.

  • ...But unfortunately both post revisions or product revisions look absolutely the same in wp_posts table comparing their post_status and post_type entries... – YKKY Jan 5 '17 at 18:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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