WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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

closed as off-topic by Pieter Goosen, cybmeta, Mark Kaplun, Otto, gmazzap Nov 22 '14 at 21:13

This question appears to be off-topic. The users who voted to close gave this specific reason:

If this question can be reworded to fit the rules in the help center, please edit the question.

Thank you so so much. You saved my lots of time. – user35698 Jul 24 '13 at 2:25
up vote 13 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:

 $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
@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

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