dgwatkins

Clean orphan comment translation data

Jul 26th, 2013
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.48 KB | None | 0 0
  1. <?php
  2. require "wp-config.php";
  3.  
  4. $rows = $wpdb->get_col("SELECT t.translation_id FROM wp_icl_translations t
  5.                LEFT JOIN wp_comments c ON t.element_id = c.comment_ID
  6.                WHERE t.element_type = 'comment' AND c.comment_ID IS NULL");
  7. echo sizeof($rows) . " to be deleted. ";
  8.  
  9. if (!empty($rows)) {
  10. $affected = $wpdb->query("DELETE FROM {$wpdb->prefix}icl_translations WHERE translation_id IN (".implode(',',$rows).")");
  11. echo $affected . " rows deleted. ";
  12. }
  13. ?>
Advertisement
Add Comment
Please, Sign In to add comment