I’m almost complete whit my wp theme an I’m now translating it with the WPML plugin. This is working out great (even all my custom post types and meta boxes 🙂 ), but of course there have to be a problem.
I have added meta boxes to one specific page and have target it like this:
add_action('admin_init','my_meta_init');
function my_meta_init()
{
$post_id = $_GET['post'] ? $_GET['post'] : $_POST['post_ID'] ;
// checks for post/page ID
if ($post_id == '17')
{
add_meta_box('meta_webdesign', 'Webdesign', 'my_meta_webdesign', 'page', 'normal', 'high');
add_meta_box('meta_grafisk', 'Grafisk design & Identitets design', 'my_meta_grafisk', 'page', 'normal', 'high');
add_meta_box('meta_illustrasjon', 'Illustrasjon', 'my_meta_illustrasjon', 'page', 'normal', 'high');
}
But now I need to also target the English version of the page (id 348), how do I do that?
Ps. I have tried this: if ($template_file == ‘page-tjenester.php’) (the Norwegian and English version both use the same template, but then all the meta boxes disappear.
I would be very grateful for help with this 🙂
I’ve got this working finally ($template_file == ‘page-tjenester.php’), so now my meta boxes shows up only when I use this specific page-template!
This is the final code if someone is interesting;
Not hard at all (not sure what I did wrong when I tried this before)
Use the icl_object_id function of WPML. It will resolve automatically the id depending of the current language.
Another option and IMO much more reliable one would be to do the check based on the slug of the page. It would cover you in the case you accidentally deletes the post/page concerned. With an ID check you would be forced to go and edit the code source again, with a slug check you’d only have to recreate a page with the same slug. Just my 2 cents though.
You could try Limon
in that case would the code look like this for page-posttype. in that case you dont have to think of the hooks and what hooks to use 🙂
https://bitbucket.org/DanelK/limon-project/src/a2d5e081249a/_README_EXAMPLES_
there are of course some more methods that you could find useful.