Sign up ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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:


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 :)

share|improve this question
Don't use $_GET, use get_query_var() instead, which provides sanitized data, even if it's for admin, I wouldn't depend on it. Have you tried adding elseif ($post_id == 348) { add_meta_box ... }? – soulseekah Oct 19 '11 at 10:03
Hi thanks for answering :), can you please show (in a context with; if ($post_id == '17') ) what you mean (I only get error)? You see, this is only my second wp theme and the first one using meta boxes and custom post types, so I'm kinda confused how to implement this! And how do I use get_query_var() in the code I've already have, and would changing this mess up my meta boxes with content? – Elisabeth Oct 19 '11 at 18:13

3 Answers 3

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.

share|improve this answer
Thank you so much for answering :). Can you show an sample of what you have in mind, how would you write this code? I'm still pretty new to everything WP (but I'm learning a elephant everyday) so good samples is my savior! – Elisabeth Oct 19 '11 at 18:23
I don't have much time now to show a code example. Basically, all you need to do is here. – Jonathan Liuti Oct 19 '11 at 21:35

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;

add_action('admin_init','my_meta_init'); function my_meta_init() {

$post_id = $_GET['post'] ? $_GET['post'] : $_POST['post_ID'] ; $template_file = get_post_meta($post_id,'_wp_page_template',TRUE);

if ($template_file == 'page-tjenester.php') { // this will only show on pages that have been saved with the page-tjenester.php template

    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');


Not hard at all (not sure what I did wrong when I tried this before) :D

share|improve this answer
You should accept this as the answer. Check out the About page and FAQ for more information on how this website works. – Ian Dunn Apr 3 '12 at 15:50

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 :)

    // Create Metabox
$custom_meta_box = new MetaBox();
$custom_meta_box->  create('meta_webdesign', 'Webdesign', 'my_meta_webdesign', 'page');
// Add some fields
$custom_meta_box->  addTextField('Design', 'tf_webdesign');

function my_meta_webdesign( $meta_fields )
    echo $meta_fields['tf_webdesign'];

there are of course some more methods that you could find useful.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.