wordpressqtranslate-x

How do I get the latest post in the selected language with qTranslate-x?


The setting in the settings=>languages for "Hide Content which is not available for the selected language." is unchecked. This is the preferred state for the whole site, but for some posts I would like to show only the latest post in the selected language. (So without the default behavior: "Sorry, this entry is only available in French.").

So far I have this code, which shows the latest post in the language it is written in, but I would like to get only the posts written in the selected language.

while ( have_posts() ) : the_post();
$mypost = get_post(get_the_ID()); 
$content = qtranxf_use('en', $mypost->post_content,false); 
echo "$content";
endwhile;

Solution

  • So in the end I've used this approach to query on a specific language:

    $mypost = array('post_type' => 'posts', 'paged' => get_query_var('paged'), 's' => '[:en]',  'posts_per_page' => 7);
    

    It adds an extra query for the keyword: [:en] or any language you want. And than you can just loop through it:

    $loop = new WP_Query($mypost);
    while ($loop->have_posts()) : $loop->the_post(); ?>
    
        <article>
            <?php the_content(); ?>
        </article>
    <?php
    endwhile;