Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

WordPress

Maja B.
Maja B.
12,984 Points

WordPress - Custm Post Type and Fields - Translation of the Custom field

Hi, I'm using a WordPress plugin Custom Post Types and Custom Fields.

I have a custom post called map and two custom field: image and description for each map.

Now, I would like to have the field description in two languages (English and Slovene).

How should I tackle this? I see two options:

  1. Buy actually having two custom fields, one for the description in English (description_eng) and the other one for the description in Slovene (description-sl). In this case I should be able to write in the code an if statement - something like, if I'm looking at the web page in English, use description_eng field; if I'm looking at the web page in Slovene, use description_sl field. But how to write this if statement? What WP functions to use? Any hint?

  2. The other possibility that I see - and I was hoping this will work but it does not - is to simply write [:en]This map shows the city of Rome[:sl]To je zemljevid Rima. in the description filed.

What would you do?

I would suggest you use Advanced Custom Fields because it is super flexible and easy to translate. Are you using WPML to manage your translations?

If you use ACF you can translate a set of custom fields to another language, so when you translate your post the fields will show up translates. The shortcodes to call the content in your template files stay the same, so you don't have to worry about different templates for each language.

Maja B.
Maja B.
12,984 Points

Hi, I am actually already using Advanced Custom Fields. So that should be OK.

But no, I'm not using WPML - however I've just checked the WPML website and yes, I guess that is one useful thing I should start using. Is it free?

At the moment I'm using qTranslate for translating things in WordPress. It's a cool plugin because it lets me write things like post title, page title, post content, page content in two different languages. But as said, for custom fields (created with ACF) I do not have that option. So you think that installing WPML will give me that option?

1 Answer

You can always look into a plugin like https://wordpress.org/plugins/acf-qtranslate/ and see if this gives you the ability to translate custom fields. I have never used qTranslate so I can't really help with that.

As for WPML, I don't think it's free, but you can get a developers license pretty cheap and use it on all your websites. WPML gives you the ability to copy your custom fields to another language, so whenever you translate a page or post the custom fields are transferred to the new language. It's also very robust and can handle almost every website, I've build large product websites using WPML and ACF and never had any real issues with it.

Maja B.
Maja B.
12,984 Points

Ok, thanks. I've had another look at the internet and it seems that ACF and WPML are a really good combination.