Polylang and custom fields: How to copy and how to not.

Polylang is a very powerful tool to enable your WordPress site to be multilingual.
The only problem, I met during development is not simple and clear way of copying of custom fields to new language posts versions.

Answer was found here [resolved] polylang not syncing custom fields
If you want to make some custom field to be common for all languages, then you need to add to your functions.php file following lines:

add_filter('pll_copy_post_metas', 'copy_post_metas');
function copy_post_metas($metas) {
      return array_merge($metas, array('my_slider_caption'));
}

If you want to make your custom field to be unique for all languages, then do the following:

add_filter('pll_copy_post_metas', 'copy_post_metas');
function copy_post_metas($metas) {
      return array_splice($metas, array('my_slider_caption'));
}

In my case, I needed to remove meta ‘my_slider_caption’ from list of registered metas in order to enable different captions for a Slider.

Leave a Reply

%d bloggers like this: