Skip to content

Instantly share code, notes, and snippets.

@crissoca
crissoca / delete.sql
Created November 21, 2015 00:54 — forked from pmgarman/delete.sql
How to find and delete orphaned product variations from WooCommerce sites.
DELETE o FROM `wp_posts` o
LEFT OUTER JOIN `wp_posts` r
ON o.post_parent = r.ID
WHERE r.id IS null AND o.post_type = 'product_variation'
@crissoca
crissoca / rebuild_image_metadata.php
Last active May 16, 2018 17:19
Rebuilds WordPress image metadata after a manual media library migration
<?php
//Source: http://www.adam-makes-websites.com/discoveries/fixing_messed_up_image_attachments_in_wordpress_that_have_no_postmeta_values
function fixWPImageMetaData() {
// Notes:
// 1) This function will not alter existing meta entries for your images. The function is to ADD meta data for the images
// without it due to manually importing them or some other kind of mess-up in your wordpress wp_postmeta table.
// 2) Always remember to take a full database backup before each run of the function!
// 3) Although only tested on fairly recent WP versions it may work as far back as v1.5+. Give it a go and let me know!