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?
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#ParametersI 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: