Created
December 17, 2021 22:22
-
-
Save JasonTheAdams/e71ba2fcb86d93c43e847c21f73add13 to your computer and use it in GitHub Desktop.
Migrates post relationships from Piklist to MetaBox
This file contains hidden or 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
set @row_num:=0; | |
INSERT INTO wp_mb_relationships | |
( | |
`to`, | |
`type`, | |
`order_from`, | |
`order_to`, | |
`from` | |
) | |
SELECT | |
m.post_id AS BelongID, | |
CONCAT(pb.post_type, "_to_", p.post_type) AS ID, | |
(@row_num:=CASE | |
WHEN @from_id = CAST(m.meta_value AS UNSIGNED) | |
THEN @row_num+1 | |
ELSE 1 | |
END | |
) AS order_from, | |
0, | |
@from_id := CAST(m.meta_value AS UNSIGNED) AS FromID | |
FROM wp_postmeta AS m | |
JOIN wp_posts AS p ON p.ID = m.post_id | |
JOIN ( SELECT ID, post_type FROM wp_posts ) AS pb | |
ON pb.ID = m.meta_value | |
WHERE m.meta_key = '__relate_post' | |
ORDER BY FromID ASC; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment