Automatically Fill Image Alt Text and ...
Learn how to automatically fill image alt text and metadata in WordPress on upload wi...

WPCodeBox
870
This snippet queries the WordPress database to find and count orphaned WooCommerce product variations, which are product variations whose main product has been deleted.
<?php
// This snippet should only run in "Manual" mode.
global $wpdb;
$orphaned_variations_results = $wpdb->get_results("SELECT * FROM {$wpdb->posts} o LEFT OUTER JOIN {$wpdb->posts} r ON o.post_parent = r.ID WHERE r.id IS null AND o.post_type = 'product_variation'");
$ov_count = count($orphaned_variations_results);
echo "There are $ov_count variations on your site.";





