Ask your WordPress questions! Pay money and get answers fast! Comodo Trusted Site Seal
Official PayPal Seal

Bulk creating Polylang taxonomy terms/categories WordPress

  • REFUNDED

Hi,

I've recently activated Polylang pro on a website with a lot of existing content (~3000+ items) spread across a number of CPTs and taxonomies. I've set up all the necessary syncing options for polylang, but they have no impact on posts / categories / taxonomy terms that already exist.

In some instances, we have a very high number of terms (for example, a boat class taxonomy with 200+ classes). This initial rollout is in 4 additional languages (French, Italian, German, and Spanish) and we will be adding more in the future. The categories / taxonomy term names are staying in English and not being translated, but they need instances created for each language set in order for the translated posts to retain their assigned posts.

Polylang support gave me this suggestion, but given the size of the website, I'd rather not screw this up. Plus, the below only refers to categories, not the other taxonomies/terms.

If I well understand, you want to automatically duplicate all your categories.

//
The fast way would be to make a small PHP script. This shouldn't be very difficult if you have som PHP knowledge.
You can for example get all your categories in English:
$terms = get_terms( array( 'taxonomy' => 'category', 'lang' => 'en' , 'hide_empty' => false ) );
Get all the languages with pll_languages list
$languages = pll_languages_list();
Then you can insert new terms with wp_insert_term
Save the language with pll_set_term_language and save the translations groups pll_save_term_translations
//

(polylang doc link: https://polylang.pro/doc/function-reference/#pll_set_term_language)

I need something to create all the necessary language variations of each existing term -- and ideally, be able to run this in the future when we add additional languages so I do not need to manually work through every single taxonomy. I'm not sure if this would be better served as a standalone script or a function -- but it does appear that even adding new taxonomy terms I still need to create each language iteration -- if a function creating all the language variations for active languages automatically, that would be awesome.

Answers (0)

No answers yet.