Ask your WordPress questions! Pay money and get answers fast! Comodo Trusted Site Seal
Official PayPal Seal

Get custom fields from main WPML language for other languages WordPress

  • SOLVED

Hi,

We are developing a website for a client in which there are references available. It's a multi-language website with the following languages: NL, FR & EN in which we use the WPML plugin. The main language is NL.

Here is the link with an example: http://www.aspbluesquare.be/category/referenties/

The following fields are custom:
- date
- location
- client
- project_manager_client
-project_manager_aspbs
- website_url
- photographer

Now we have to enter the reference with the custom fields first in the main language (NL in this case). Then we have to do it twice again for the FR and EN version. The content is always the same.

So we are looking for a way to display the custom fields of the NL version on the front-end version of de FR & EN version.

If you have any question don't hesitate to give a yell.

Answers (1)

2010-12-22

Peter Michael answers:

Try this:


// Get the post ID (in this case the english one)
$o_ID = icl_object_id($post->ID, 'post', false, 'en');
// Now get the custom fields
$date_en = get_post_meta($o_ID, 'date', true);
$location_en = get_post_meta($o_ID, 'location', true);
$client_en = get_post_meta($o_ID, 'client', true);


Filip Van Reeth comments:

Nopes, does not work.
I tried it with the date:

NL: http://www.aspbluesquare.be/referenties/beurzen/ondernemen-2008/
EN: http://www.aspbluesquare.be/en/references-en/ondernemenentreprendre-2008/

The code i used on the single page of the EN version:

<div class="info"><?php $o_ID = icl_object_id($post->ID, 'post', false, 'en');

// Now get the custom fields

$date_en = get_post_meta($o_ID, 'date', true); ?></div>


Thanks for the quick response.


Filip Van Reeth comments:

Hi,
Is there also a way to get the featured image?


Peter Michael comments:

Is $post global? Did you global $post; somewhere? I.E:

global $post;
$o_ID = icl_object_id($post->ID, 'post', false, 'en');
...


Filip Van Reeth comments:

Hi,
This is my code:


<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<div <?php post_class() ?> id="post-<?php the_ID(); ?>">
<h1><?php the_title(); ?></h1>
<div class="specs">
<div class="label">Date:</div>
<div class="info">
<?php $o_ID = icl_object_id($post->ID, 'post', false, 'en');
$date_en = get_post_meta($o_ID, 'date', true); ?></div>
</div>
<div class="clear"></div>
<div class="specs">
<div class="label">Location:</div>
<div class="info"><?php $key="location"; echo get_post_meta($post->ID, $key, true); ?></div>
</div>
<div class="clear"></div>
<div class="specs">
<div class="label">Client:</div>
<div class="info"><?php $key="client"; echo get_post_meta($post->ID, $key, true); ?></div>
</div>
<div class="clear"></div>
<h3 class="references">Project managers</h3>
<div class="specs">
<div class="label">Client:</div>
<div class="info"><?php $key="project_manager_client"; echo get_post_meta($post->ID, $key, true); ?></div>
</div>
<div class="clear"></div>
<div class="specs">
<div class="label">ASP Blue Square:</div>
<div class="info"><?php $key="project_manager_aspbs"; echo get_post_meta($post->ID, $key, true); ?></div>
</div>
<div class="clear"></div>

<h3 class="references" style="color:#457db5;">Information</h3>

<div class="description"><?php the_content('<p>Read the rest of this entry &raquo;</p>'); ?>
<?php if (function_exists('sociable_html')) { echo sociable_html(); } ?>
<?php wp_link_pages(array('before' => '<p><strong>Pages:</strong> ', 'after' => '</p>', 'next_or_number' => 'number')); ?>
<?php the_tags( '<p>Tags: ', ', ', '</p>'); ?>
</div>
<p><?php edit_post_link('Edit this entry','','.'); ?></p>
</div>
<?php endwhile; else: ?>
<p>Sorry, no posts matched your criteria.</p>
<?php endif; ?>



Peter Michael comments:

You have PM.


Peter Michael comments:

You need to echo $date_en;