Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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?

share|improve this question

2 Answers 2

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>
share|improve this answer

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>

I wrote a WPML Setup Guide the other day, perhaps you want to take a look at that to see whether you have it all properly set up?

share|improve this answer
    
I'll take a look. Thanks so much! –  lillyanka Feb 23 '12 at 19:47

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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