Support » Plugin: Polylang » Copy custom meta when creating translations

  • Resolved winnewoerp

    (@joschi81)


    Hi Chouby,

    thanks for your great plugin. I’m using it quite often and it works very fine.

    I just got one question: Is there a way to copy (e.g.) custom meta automatically to new translations of a page or post without synchronization between the language versions? In other words: How to automatically populate custom meta fields initially with the respective contents from another language version of a post or page?

    Kind regards
    joschi81

    https://wordpress.org/plugins/polylang/

Viewing 8 replies - 1 through 8 (of 8 total)
  • Hi,

    if you mean post meta, you can use the pll_copy_post_metas filter.

    Cheers,
    Česlav

    Thread Starter winnewoerp

    (@joschi81)

    Hi Česlav,

    thanks for your reply. I did it like this:

    // copy selected post metas for polylang plugin
    add_filter('pll_copy_post_metas', 'copy_post_metas');
    function copy_post_metas($metas) {
        return array_merge($metas, array('konzertdaten_konzertdatum','konzertdaten_konzertdatum_archiv'));
    }

    However, it’s being copied _and_ synchronized. I don’t see how to disable synchronization. Where do I have to put the respective argument?

    Kind regards
    joschi81

    Thread Starter winnewoerp

    (@joschi81)

    PS: And is it also possible to copy post title and content when a translation is created – without synchronization during the following changes?

    Hi joschi,

    You should check the second argument ($sync) in function hooked up to the filter:

    // copy selected post metas for polylang plugin
    add_filter('pll_copy_post_metas', 'copy_post_metas', 10, 2);
    function copy_post_metas($metas, $sync) {
      if ( $sync ) {
        // If syncing, ignore custom meta.
        return $metas;
      }
      else {
        // Otherwise (when creating new translation) copy custom meta.
        return array_merge(
          $metas,
          array(
            'konzertdaten_konzertdatum',
            'konzertdaten_konzertdatum_archiv'
          )
        );
      }
    }
    

    Hope that helps,
    Česlav

    Thread Starter winnewoerp

    (@joschi81)

    That works, thank you very much. Now, the only question is how to copy title and content initially to new translations. Is tehre a way to achieve that?

    Thread Starter winnewoerp

    (@joschi81)

    Resolved, I found the solution for copying title and content to new translations here:
    http://www.junaidbhura.com/make-polylang-wordpress-plugin-copy-the-content-from-the-original-post/

    Thus, thanks junaid – and thanks again Česlav for the great plugin.

    Hi joshi,

    I’m glad I could help, but I’m not the author of Polylang, so your thanks should go to Chouby 🙂

    Cheers,
    Česlav

    Thread Starter winnewoerp

    (@joschi81)

    Yes, sorry… 🙂 Like this:
    Thanks Česlav for your help and thanks Chouby for the great plugin!

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Copy custom meta when creating translations’ is closed to new replies.