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

How to create custom post types in multisite install for multilingual purposes

Hello, I'm wrapping up the "how to build a wordpress theme" series and I am about to embark on creating my first custom post type. However, my context is slightly different as i am creating a multilingual site using multisite with a language switcher, allowing visitors to jump from an English custom post type (workshop) to its French equivalent (formation).

I am pretty certain I can follow this and other tutorials in order to create the custom post type in one language, but my question is how do I go about dealing with the the second language? Does the theme require two separate CPTs (one for each lang) or is there some sort of conditional code added to allow both sites to use a single CPT?

My goal was to create this in a plugin (future proof the content in case of theme change down the line) so again would love someone to point me in the right direction and at least let me know if I am creating a single plugin/CPT or two...and where I should put all the code? There will be some custom meta boxes and possibly custom fields so I assume those will also need the same consideration.

Thanks.

Anyone have any ideas on this? Perhaps Zac Gordon might have a solution for this one?

4 Answers

Zac Gordon
STAFF
Zac Gordon
Treehouse Guest Teacher

Hey man,

I would suggest using this instead of trying to tackle the problem yourself: http://wpml.org/

There are a lot of complexities with multilingual projects that this plugin solves really well.

Nick Pettit
STAFF
Nick Pettit
Treehouse Teacher

Hi lucas lemonnier,

Indeed, Zac Gordon might have a better answer here. However it sounds like you want to look into the i18n (internationalization) features of WordPress. Here's a link to the codex page where you can learn more: http://codex.wordpress.org/I18n_for_WordPress_Developers

Thanks to you both for the feedback. Zac Gordon I am familiar with wpml, but it has its own set of issues (big speed hits being one of them) and these two sites, while sharing a common content structure, will actually be populated by different content. I guess what I am wondering is if there is a way to make a single CPT (as a Plugin) which can be used by each site, or if I am better off creating 2 different ones (ex: "CPT-french" and "CPT-english")?

Thanks again!

Zac Gordon
STAFF
Zac Gordon
Treehouse Guest Teacher

If you use the same post and have different fields for the different languages then you're going to have some issues like having the same url and same title for the same entries. You may want to look into having related posts so you can identify which posts are the same entries but you can have custom title, urls, categories, tags etc.

Thanks. Someone also suggested that a single CPT (built as a plugin) and then using the built-in wordpress localization features and a language switcher may be all that's needed. Seems the most straightforward and least "hacky" approach.