I am doing a special migration from someone's custom CMS to a WP installation. I successfully got the posts and comments migrated into their respective tables. Now I need to get the comment count into the wp_posts table for each matching id. I have something like this. I'm close, I think:
SELECT COUNT(comment_content) AS total_comments, comment_post_ID AS commentID FROM wp_comments GROUP BY comment_post_ID; --mysql won't let me run the group by on just the returned count column, so I'm stuck with two columns of data when I just want to insert one UPDATE wp_posts SET comment_count = total_comments WHERE wp_posts.ID = commentID; --So I tried to set my returned data to variables and assign them into the update statement..which doesn't work
Anyway, perhaps I need to iterate all the posts, find a matching ID and update it by moving the cursor? Or is there an easier way i'm missing somehow?