1

I have a Wordpress site translated from dansk to english using WPML. In it, I have a page which uses a custom page template to display the titles of all the posts. Sadly, it's displaying all posts twice: the original, and the translated.

This is the code I have:

<ul id="archive-list">
    <?php $args = array(
        'lang' => ICL_LANGUAGE_CODE,
        'numberposts' => '-1',
        'post_type' => 'post',
    );

    $myposts = get_posts($args);

    foreach($myposts as $post) : ?>
        <li><a href="<?php the_permalink(); ?>"><?php   the_title(); ?></a></li>
    <?php endforeach; ?>
</ul>

Does anyone have any idea what I need to do to get this page to display only the titles in the current language?

3

For the language filter from WPML to take effect you have to allow filters in get_posts. Default this is off.

You can add suppress_filters=0 to your get_posts args and it should work. See: http://codex.wordpress.org/Template_Tags/get_posts#Parameters

<ul id="archive-list">
    <?php $args = array( 'suppress_filters' => false, 'numberposts' => '-1', 'post_type' => 'post', );
    $myposts = get_posts($args);
    foreach($myposts as $post) : ?>
    <li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
    <?php endforeach; ?>
</ul>
1

I think the reason that it is showing content in all languages, is because the language code arg should not be in the array.

I usually don't use surpress filters either.

If you have WPML properly set up, then you can go ahead and just use a custom query sth like:

<h2><?php _e('Archive','textdomain'); ?></h2>
   <ul id="archive-list">
      <?php $loop1 = new WP_Query( array( 'post_type' => 'post', 'posts_per_page' => -1 ) ); ?>
      <?php while ( $loop1->have_posts() ) : $loop1->the_post(); ?>
      <li><a href="<?php the_permalink(); ?>" title="<?php printf( esc_attr__( 'Link to %s', 'textdomain' ), the_title_attribute( 'echo=0' ) ); ?>"><?php the_title(); ?></a></li>
      <?php endwhile; ?>
   </ul>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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