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.

How do you get the content by id and by specific language?

I need to display two specific language content in a page, regardless of the session's language. So far, this is my progress: this works fine for getting the content by id of the active language:

<?php $id=47; $post = get_page($id); $content = apply_filters('the_content', $post->post_content); echo $content;  ?>

How to apply a specific language to the filter?

Thanks for the help. Sziro

share|improve this question
    
Thank you so so much. You saved my lots of time. –  user35698 Jul 24 '13 at 2:25
add comment

1 Answer

up vote 9 down vote accepted

You must use the qTranslate native functions to do your job. Use qtrans_use, that is the function that do all the job in qTranslate. It's defined in qtranslate_core.php, line 747

function qtrans_use($lang, $text, $show_available=false) 

Use it on the raw content of the post!

Try this code:

<?php 
 $id=47; $post = get_page($id); 
 $content = qtrans_use('en', $post->post_content,false); 
 echo $content;  
?>

In this example, it will return the English version of your text! Substitute it with the desired language identifier to translate into another language!

share|improve this answer
    
That did it, thanks! –  user1348490 May 12 '12 at 14:14
    
Yes, glad to have helped you! –  keatch May 12 '12 at 14:58
    
This works perfectly, but it took me a few attempts to realise that the get_page($id) bit is important. By the time you're rendering the view, qTranslate has already modified the contents of $post to only contain the current language, so you need to load it again to get the options for all languages. –  Marcus Downing Jul 26 '12 at 12:57
    
@keatch can you help me with this plugin it keep on showing english text always, I have installed it properly, do i need to make any other changes in code? or it will work normally without doing anything –  Jack Sep 10 '12 at 10:31
1  
@ShivanRaptor to get the current language identifier you can use many ways but most recommended is: qtrans_getLanguage(). –  Lenin Oct 20 '13 at 10:45
show 2 more comments

Your Answer

 
discard

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.