This is the technical support forum for WPML - the multilingual WordPress plugin.

Everyone can read, but only WPML clients can post here. WPML team is replying on the forum 6 days per week, 22 hours per day.

This topic contains 1 reply, has 2 voices, and was last updated by  Mihai 8 years, 3 months ago.

Author Posts
Author Posts
October 30, 2009 at 11:02 am #13366


Hi there,
I am setting up my first bi-lingual blog with WPML, and as I'm not a PHP programmer, I'm having problems with what must be a simple issue. My sidebar lists recent posts. However, it is listing recent posts in all languages. I would like the sidebar to list the recent posts in whatever language the blog is being displayed in. The code in use currently is this:

<?php $posts = get_posts("numberposts=10&orderby=post_date&order=DESC"); foreach($posts as $post) : ?>

<li><a>"><?php the_title(); ?></a> - <?php the_ID(); ?></li>
 <?php endforeach; ?>

I will have the same issue with tags and comments.
I know I can use ICL_LANGUAGE_CODE to find the language the page is being displayted in, but how do I get a post's language code? Sorry if this is too basic, but I'm not a programmer and this looks like something so simple...

November 2, 2009 at 8:32 pm #13368

Forum moderator

The function get_posts() is sendinfg suppress_filters=1 by default to thw WP query that's being generated.
What you can do is add suppress_filters=0 as an argument:

<?php $posts = get_posts("numberposts=10&orderby=post_date&order=DES&suppress_filters=0"); foreach($posts as $post) : ?>

This will ensure that the WPML filters will be used so you should see the posts in the correct language.

The topic ‘[Closed] Lists posts by language’ is closed to new replies.