insert into wp_term_relationships select a.id, 48, 0 from wp_posts as a where a.post_type = 'tcp_product' update wp_posts as a inner join ( select id, replace(post_title, ' ', '-') as post_title from wp_posts where (post_type = 'tcp_product') ) as b on ((a.post_title = b.post_title)) set a.post_parent = b.id where ((a.post_parent is null) or (a.post_parent = 0)) and (a.post_type = 'attachment') insert into wp_postmeta (post_id, meta_key) select a.id, '_thumbnail_id' from wp_posts as a where a.post_type = 'tcp_product' update wp_postmeta as a inner join ( select id, post_parent, post_title from wp_posts where (post_type = 'attachment') ) as b on ((a.meta_key = '_thumbnail_id') and (a.meta_value is null) and (a.post_id = b.post_parent)) set a.meta_value = b.id