WP_Query and polylang issue

OK – I got it, the old posts already on the database do NOT have an english translation and that’s the problem with my loop. When I add a new post, I have the option to provide a translation which then appears in the english page.

looking through the docs I found that I can also show the default when there is no translation by something like :

<?php query_posts(array('post_type' => 'post','lang' => 'fr')); // force querying the French posts ?>
if (have_posts()) : ?>
    <?php while (have_posts()) : the_post(); ?>
    <?php global $post;
    if($post_id = pll_get_post($post->ID, pll_current_language())) { // get translated post (in current language) if exists
        $post = get_post($post_id);
        setup_postdata($post);
    }?>

… do what ever you want in your loop …

Leave a Comment