Skip Navigation

This thread is resolved. Here is a description of the problem and solution.

Problem:
You are using a WP Query to retrieve posts in a specific language, but the query returns posts in both languages despite the permalinks being correct.
Solution:
We recommend adding the

suppress_filters => false

parameter to your query. By default, the

get_posts()

function has

suppress_filters

set to true, which you need to explicitly override. Here's how you can modify your query:

$posts = get_posts(array( 'post_type' => 'post', 'posts_per_page' => 2, 'orderby' => 'date', 'order' => 'DESC', 'post__not_in' => array(get_the_ID()), 'suppress_filters' => false ));

This change should ensure that the query only returns posts from the selected language.

If this solution does not resolve your issue or seems outdated, we highly recommend checking related known issues at https://wpml.org/known-issues/, verifying the version of the permanent fix, and confirming that you have installed the latest versions of themes and plugins. If further assistance is needed, please do not hesitate to open a new support ticket at WPML support forum.

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.

Tagged: 

This topic contains 1 reply, has 0 voices.

Last updated by Marcel 1 month ago.

Assisted by: Marcel.

Author Posts
January 23, 2025 at 9:46 am #16626317

nilsF-4

Background of the issue:
I am trying to use a simple WP Query in one of my blocks to retrieve posts. The code I am using is: $posts = get_posts(array( 'post_type' => 'post', 'posts_per_page' => 2, 'orderby' => 'date', 'order' => 'DESC', 'post__not_in' => array(get_the_ID()) ));. The issue can be seen on this page: hidden link.

Symptoms:
Somehow this query returns posts in both languages, but the permalinks to the posts are correct. I expected to see only posts from the selected language, but instead, I got posts from the wrong language.

Questions:
Why does the WP Query return posts in both languages?
How can I modify the query to only show posts from the selected language?

January 23, 2025 at 11:18 am #16627441

Marcel
Supporter

Languages: English (English ) German (Deutsch )

Timezone: Europe/Madrid (GMT+01:00)

Hi,

Please add this parameter to your query:

suppress_filters => false,

On get_posts() it's per default true, you need to define it yourself (compared to WP_QUERY).

Best Regards,
Marcel