Created
November 20, 2011 06:47
-
-
Save backflip/1379907 to your computer and use it in GitHub Desktop.
WordPress: WPML: Update comments table
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
UPDATE wp_posts wpp LEFT JOIN (SELECT comment_post_id AS c_post_id, count(*) AS cnt FROM wp_comments WHERE comment_approved = 1 GROUP BY comment_post_id) wpc ON wpp.id=wpc.c_post_id SET wpp.comment_count=wpc.cnt WHERE wpp.post_type IN ('post', 'page') AND (wpp.comment_count!=wpc.cnt OR (wpp.comment_count != 0 AND wpc.cnt IS NULL)); | |
SET @trid = (SELECT MAX(trid) FROM wp_icl_translations); | |
INSERT INTO wp_icl_translations (element_type, element_id, trid, language_code) | |
SELECT 'comment', missing_comments.comment_ID, (@trid:=@trid+1) AS trid, language_code | |
FROM wp_icl_translations | |
RIGHT JOIN ( | |
SELECT comment_ID, comment_post_ID FROM wp_comments | |
WHERE NOT EXISTS ( | |
SELECT * FROM wp_icl_translations | |
WHERE wp_comments.comment_ID = wp_icl_translations.element_id | |
AND wp_icl_translations.element_type = 'comment' | |
)) AS missing_comments | |
ON missing_comments.comment_post_ID = wp_icl_translations.element_id | |
WHERE wp_icl_translations.element_type = 'post_post' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment