Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

My client uses WPML to translate their content posts. I am finalizing the adaptation of their WordPress project, and I am faced with an issue where I can only retrieve posts in the base language, namely English. Below is my code:

<!-- loop through posts start -->
    $max_posts = 5;
    $i = 0;

    // do not use query_posts
    // see http://wordpress.stackexchange.com/questions/69609/why-is-custom-template-not-seen-as-page-with-is-page/69618
    // see http://codex.wordpress.org/Class_Reference/WP_Query
    // query according to language
    if($language == FR)
        $query = new WP_Query('category_name=nouvelles,portfolio-fr');
        $query = new WP_Query('category_name=news,portfolio');

    while($i < $max_posts):
        $id = $query->post->ID;
        $title = get_the_title($id);
        $date = get_the_date();
        $permalink = $query->post->guid;


        href="<?php echo $permalink; ?>" 
        <span class="title"><?php echo $title; ?></span>
        <span class="date"><?php echo $date; ?></span>

<!-- loop through posts end -->

Basically, this works fine in English, but on the French side, even though the categories are right, and the post is in the proper category, there is no content.

Below is a comparison between the English posts list (left), and the French posts list. WPML somehow links the two together.

Link to image: http://i.stack.imgur.com/bGefM.png (site prevents me from posting an image...)

I would like to know what to do to get the content? Thanks.

share|improve this question
in your code above $language doesn't seem to be defined. Apart from that WPML doesn't use it like that, but instead: if ( ICL_LANGUAGE_CODE == 'fr' ) { // do something } elseif ( ICL_LANGUAGE_CODE == 'en' ) { // do something else } Then for the query you should use icl_object_id and if you'd use that properly, then there won't be the need to use the if/else condition. All the info you need you can find on wpml.org –  Piet Nov 16 '12 at 4:40
Sorry if that wasnt clear, but I define $language earlier on. That is not the issue currently. What do you mean about the icl_object_id? I'm trying to understand and I'm not sure what this is. As for the WPML website, I asked a question there, to no avail. No need to downvote a question that needs a legitimate answer. –  jansensan Nov 16 '12 at 5:30
I downvoted the question because all the information you're after can be found on the WPML website. And the website of WPML is far bigger than their forum... –  Piet Nov 16 '12 at 9:37
add comment

1 Answer 1

use the icl_object_id() function to get the news and portfolio categories in both languages:

icl_object_id(array(x,y), 'category', true)

where x is the news category ID in the default language and y is the portfolio category ID in the default language

share|improve this answer
add comment

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.