Skip to content

Instantly share code, notes, and snippets.

@wturnerharris
Created October 26, 2018 21:28
Show Gist options
  • Save wturnerharris/68ed59c171a4e35697ca8c834c4a6183 to your computer and use it in GitHub Desktop.
Save wturnerharris/68ed59c171a4e35697ca8c834c4a6183 to your computer and use it in GitHub Desktop.
Stored procedure to migrate some meta fields to mapped ACF fields
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