Last active
September 29, 2020 15:02
-
-
Save slackday/947569a2adf7300e26027a920a20ede0 to your computer and use it in GitHub Desktop.
WordPress ACF rename field after converting to repeater
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
-- This transaction converts previous acf file field named | |
-- 'course_field_schedule_file' into acf repeater field | |
-- containing single file field | |
START TRANSACTION; | |
SET @repeater_name = 'course_field_schedule_file'; | |
SET @field_name = 'file'; | |
INSERT INTO | |
wp_postmeta (post_id, meta_key, meta_value) | |
SELECT post_id, CONCAT(@repeater_name, '_0_', @field_name), meta_value FROM wp_postmeta WHERE meta_key = @repeater_name AND meta_value != ''; | |
UPDATE wp_postmeta | |
SET meta_value = 1 | |
WHERE meta_id IN ( | |
SELECT * FROM (SELECT meta_id FROM wp_postmeta WHERE meta_key = @repeater_name AND meta_value != '') AS p | |
); | |
COMMIT; | |
-- Disclaimer: Use at your own risk! NO WARRANTY! Make backup before use and test on local environment first! :-) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment