2
votes

I've create some custom posts on my customized theme in wordpress, in which the polylang plugin is activated.

The translation works well, but the problem is that I need that specified contents remain the same between translated posts. With the normal posts you can deactivate the translation for the media type, but this will not apply for custom content type.

For example, if I got two languages, like English and Spanish, and I create a new custom english post:

[ENG POST]
TITLE
content1 *
content2
media1 *
media2

I'd want that on the spanish post some of the contents to be already populated with some of the contents that I've already written\uploaded in the english post (the ones with the "*" ), like:

[SP POST]
-empty-
content1
-empty-
media1
-empty-

For the custom posts I'm using the CMB2 plugin.

Is there an elegant way to do this?

3

3 Answers

0
votes

From what i know WPML is pretty good for multi language websites, if you like, you can try it... WordPress has always problems with plugins....

0
votes

Never done anything like that, but to my knowledge polylang creates another post and, when loading the new language form, completely reloads CMB2 fields, triggering all related events.

Getting in the right event and finding the original post id should allow you to set the previous values as default for the corresponding fields, but it's just theory, since I never really tried. Let me know if it works.

0
votes

If you use CMB2's custom fields to create those parts of the custom post type content, here is the more or less elegant, straightforward way to achieve the goal.

Create the wpml-config.xml file (it's pretty self-explanatory)

<wpml-config>
    <custom-fields>
        <custom-field action="copy">cf_content_to_populate</custom-field>
        <custom-field action="copy">cf_media_to_populate</custom-field>
        <custom-field action="translate">cf_content_to_translate</custom-field>
        <custom-field action="translate">cf_media_to_translate</custom-field>
    </custom-fields>
</wpml-config>

and save it to the root directory of the theme you use.

cf_content_to_populate and cf_media_to_populate will be available all over the languages without translation, but cf_content_to_translate and cf_media_to_translate will require translation.

Using wpml-config.xml you can manage copying and/or translation of

  • specified custom fields;
  • specified custom post types;
  • specified taxonomies;
  • specified admin texts as custom plugin or custom theme options etc..

But you can't do this on per-post basis out-of-the-box.

Official Polylang documentation on The wpml-config.xml file.