Created
October 26, 2018 21:28
-
-
Save wturnerharris/68ed59c171a4e35697ca8c834c4a6183 to your computer and use it in GitHub Desktop.
Stored procedure to migrate some meta fields to mapped ACF fields
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
DROP PROCEDURE IF EXISTS STEPBYSTEP; | |
DELIMITER ;; | |
CREATE PROCEDURE STEPBYSTEP() | |
BEGIN | |
DECLARE done INT DEFAULT FALSE; | |
DECLARE POST_ID INT DEFAULT 0; | |
DECLARE cursor_results CURSOR FOR SELECT ID FROM wp_posts WHERE post_type = 'press_materials'; | |
DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = TRUE; | |
OPEN cursor_results; | |
read_loop: LOOP | |
FETCH cursor_results INTO POST_ID; | |
IF done THEN | |
LEAVE read_loop; | |
END IF; | |
INSERT INTO `wp_postmeta` (`post_id`, `meta_key`, `meta_value`) | |
VALUES | |
(POST_ID, '_youtube_link', 'field_5bb647ff03065'), | |
(POST_ID, '_credits', 'field_5bb6482903066'), | |
(POST_ID, '_year', 'field_5bb6483503067'), | |
(POST_ID, '_embed_code', 'field_5bb6484103068'), | |
(POST_ID, '_download_link', 'field_5bb6484d03069'), | |
(POST_ID, '_thumbnail', 'field_5bb648540306a'); | |
END LOOP; | |
CLOSE cursor_results; | |
END; | |
;; | |
DELIMITER ; | |
CALL STEPBYSTEP(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment