Accessing content for non-active languages with qTranslate

I’ve recently been working on a new site for a large Jewish philanthropic organization, developing a (very) custom WordPress theme for their site– when it came to coming up with a way to handle bilingual English/Hebrew content, we tried a few WordPress plugins before settling on Qian Qin’s qTranslate, which has been wonderful– great user interface, easy for the client to grasp, easy to work with.  The one problem I encountered way that there is no easy way to reach across languages for content, which was necessary for one section of the site where English content needed to appear alongside Hebrew content.  Without any further ado, here’s the snippet of code I came up with to get at both languages– you are left with $p_title and $p_body which are both arrays, and you need to make sure to substitute your language in for Hebrew, and your language 2 letter code in for iw on line 3:

$enddelim = '<!--:-->';
 $englishdelim = '<!--:en-->';
 $hebrewdelim = '<!--:iw-->';

 $getpost = get_posts('post_type=page&include='.$post->ID);
 foreach($getpost as $p2) :
 $both_titles = 'blah'.$p2->post_title;
 $both_bodies = 'blah'.$p2->post_content;

 if(strpos($both_titles, $englishdelim)) :
 $pt1 = explode($englishdelim, $both_titles);
 $pt2 = explode($enddelim, $pt1[1]);
 $p_title['english'] = $pt2[0];

 if(strpos($both_titles, $hebrewdelim)) :
 $pt1 = explode($hebrewdelim, $both_titles);
 $pt2 = explode($enddelim, $pt1[1]);
 $p_title['hebrew'] = $pt2[0];

 if(strpos($both_bodies, $englishdelim)) :
 $pt1 = explode($englishdelim, $both_bodies);
 $pt2 = explode($enddelim, $pt1[1]);
 $p_body['english'] = $pt2[0];

 if(strpos($both_bodies, $hebrewdelim)) :
 $pt1 = explode($hebrewdelim, $both_bodies);
 $pt2 = explode($enddelim, $pt1[1]);
 $p_body['hebrew'] = $pt2[0];

One Response to “Accessing content for non-active languages with qTranslate”

  1. Jacky Andrew

    Doing the same thing, but with much less:

    $getpost = get_post($post->ID);

    if (preg_match_all('/–>(.+?)<!–:–>/', $getpost->post_title, $titles)):

    $titles = $titles[1];


    if (preg_match_all('/–>(.+?)<!–:–>/', $getpost->post_content, $content)):

    $content = $content[1];


    Now your titles are in an array $titles. $titles[0] being english and $titles[1] being hebrew. Same for the content with $content.


Leave a Reply

Your email address will not be published. Required fields are marked *