acf-options-for-polylang icon indicating copy to clipboard operation
acf-options-for-polylang copied to clipboard

Manipulate data from one lang to an other one

Open davidfaber opened this issue 6 years ago • 4 comments

Hi there, Thank you so much for this awesome plugin. One thing though.... I recently added it to an existing site of mine and I came up with an SQL-Script that does two things:

  1. It moves all stored data from "All languages" to en_GB
  2. It copies existing fields to a new language (de_DE) in my case

I think this can be very useful for other users too, e.g. if add the plugin to an existing site or you add a new language and don't want to start from 0 with your settings.

Also it cleans up the "All languages"-data, which could be a good solution for Issue #37

If you tell me where and how you would like that information in your Readme, I am very happy to make the changes and open an Pull request for it.

The MySQL:

# Rename current options
UPDATE {YOUR_TABLE_PREFIX}options SET option_name = CONCAT('options_en_GB', TRIM(LEADING 'options' FROM option_name)) WHERE option_name LIKE 'options%';
UPDATE {YOUR_TABLE_PREFIX}options SET option_name = CONCAT('_options_en_GB', TRIM(LEADING '_options' FROM option_name)) WHERE option_name LIKE '_options%';

# Duplicate options
CREATE TEMPORARY TABLE tmptable_1 SELECT * FROM {YOUR_TABLE_PREFIX}options WHERE option_name LIKE 'options%' OR option_name LIKE '_options%';
UPDATE tmptable_1 SET option_id = NULL;
UPDATE tmptable_1 SET option_name = CONCAT('options_de_DE', TRIM(Leading 'options_en_GB' FROM option_name)) WHERE option_name LIKE 'options%';
UPDATE tmptable_1 SET option_name = CONCAT('_options_de_DE', TRIM(Leading '_options_en_GB' FROM option_name)) WHERE option_name LIKE '_options%';
INSERT INTO {YOUR_TABLE_PREFIX}options SELECT * FROM tmptable_1;
DROP TEMPORARY TABLE IF EXISTS tmptable_1;

# Show the results
SELECT * FROM {YOUR_TABLE_PREFIX}options WHERE option_name LIKE 'options%' OR option_name LIKE '_options%';

Thanks, David

davidfaber avatar Feb 09 '19 09:02 davidfaber

Thank you David,

You summed up everything perfectly.

I have to take a look.

MaximeCulea avatar Feb 11 '19 15:02 MaximeCulea

It seems nice.

I will make a wp cli command to :

  • copie "all languages" values to an other
  • copie specific language values to an other

MaximeCulea avatar Apr 11 '19 07:04 MaximeCulea

That sounds like a lovely idea!

davidfaber avatar Apr 11 '19 07:04 davidfaber

Hi, can you add as link to right metabox?

1ucay avatar Oct 05 '20 12:10 1ucay