Skip to content Skip to sidebar

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

Problem:
The client is experiencing an issue where a custom post type 'projekt' displays duplicate entries in a secondary language (Swedish) despite setting the language parameter in WP_Query. The query fetches posts from both the default (Polish) and secondary language, leading to content duplication on the Swedish page.
Solution:
We recommended removing the 'lang' => $current_lang from the WP_Query and testing without it. If the issue persists, it might be related to other parts of the custom code. We advised testing the issue in a minimal environment using a default WordPress theme and only essential plugins to confirm if the problem is related to WPML or the custom code. Additionally, we provided a working code example for querying WooCommerce products to demonstrate a similar setup that functions correctly. If the problem continues, further debugging of the custom code or consultation with a developer might be necessary.

Please note that this solution might be outdated or not applicable to your specific case. 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 the issue persists, please 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 15 replies, has 0 voices.

Last updated by Laura 2 weeks, 6 days ago.

Assisted by: Dražen.

Author Posts
August 29, 2025 at 12:41 pm #17358120

maciej-motlawskiI

Background of the issue:
I am trying to display a custom post type called 'projekt' on my WordPress site using WPML. On my default language page (Polish, pl), the query correctly fetches only the Polish posts. However, on a translated page (Swedish, sv), the query incorrectly fetches posts from both Swedish and Polish, resulting in duplicate entries on the page. My Code: PHP $current_lang = apply_filters('wpml_current_language', NULL); $projects_args = array( 'post_type' => 'projekt', 'posts_per_page' => -1, 'post_status' => 'publish', 'orderby' => 'menu_order', 'order' => 'ASC', 'suppress_filters' => false, 'lang' => $current_lang, ); $projects = new WP_Query($projects_args);

Symptoms:
Despite setting the language parameter in the WP_Query, the query returns posts from all languages, not just the current language, resulting in duplicate entries.

Questions:
What could be causing the WP_Query to ignore the language parameter?
Are there any further steps to debug why the language filter is being ignored?

September 1, 2025 at 9:47 am #17361937

Dražen
Supporter

Languages: English (English )

Timezone: Europe/Zagreb (GMT+02:00)

Hello,

thanks for reaching out to us.

Can you please try to remove

'lang' => $current_lang

, and try without.

If you still face issue, might be related to some other part of custom code, and I would advise checking in minimal and WP default theme, with only that code to see if it works fine or not.

Let me know how it goes.

Regards,
Drazen

September 1, 2025 at 9:51 am #17361942

maciej-motlawskiI

Hello,

The main issue, and the reason I am seeking a solution, is that the problem occurs within a custom, hand-coded theme that is a mandatory part of this project. Therefore, switching to a default WordPress theme to test is not a viable long-term solution, as the fix must be implemented within the current theme's architecture.

After further extensive debugging, I have managed to pinpoint the root cause of the content duplication. It's not an issue with the WP_Query itself, but a more fundamental problem.

The key finding is this: I receive an "Invalid post type" error in the WordPress admin panel when I switch the backend language from our default (Polish) to any other language (e.g., Swedish).

September 1, 2025 at 9:54 am #17361944

Dražen
Supporter

Languages: English (English )

Timezone: Europe/Zagreb (GMT+02:00)

Hello,

thank you for getting back to us.

I understand your concern, but unfortunately, as per our support policy
, we’re unable to debug or provide support for custom-coded solutions.

- https://wpml.org/purchase/support-policy/

To confirm whether the issue is related to WPML, please try reproducing it using a default WordPress theme and only the minimal required plugins. If the problem persists, we’ll be happy to investigate further. If it turns out to be related to custom code, you may need to review it on your end or consult a developer for assistance.

Best regards,
Dražen

September 1, 2025 at 10:12 am #17362012

maciej-motlawskiI

Hi Drazen,

Thank you for your response. I understand and respect the policy that you cannot provide direct support for custom themes.

However, I would like to reframe my issue, as I believe the specific problem I'm seeing—the duplication of content—is directly related to how the WPML plugin functions, rather than just being a simple theme bug.

To be clear: translations are being saved correctly, and the system works perfectly in the primary language. The issue is exclusively with how WPML handles the display of content in secondary languages.

When the Swedish page is loaded, the content is duplicated, showing both Polish and Swedish text together. This specific behavior—the mixing of two languages in the final output—seems to be a fallback mechanism within the WPML plugin itself.

My question is about this specific functionality. Is this content duplication the expected outcome when WPML encounters a configuration issue? I am trying to understand the logic that causes WPML to display content from the default language alongside the translated content, instead of showing an error or simply not displaying the post.

It seems to be a problem with the configuration and how WPML processes the content, which I don't fully understand in this context. Any insight you could provide into how WPML's rendering and fallback mechanisms work would be a great help in resolving this.

Thank you for your time.

September 1, 2025 at 10:30 am #17362063

Dražen
Supporter

Languages: English (English )

Timezone: Europe/Zagreb (GMT+02:00)

Hello,

thanks for getting back I will be glad to help out further on any doubt.

This is not regular behavior from WPML, it shows content only in that language.

Only time it can show default language post if the post is not translated and you have chosen fallback option for that post type from WPML > Settings > Post type settings.

- https://wpml.org/documentation/translating-your-contents/displaying-untranslated-content-on-pages-in-secondary-languages/#fallback-content

Regards,
Drazen

September 1, 2025 at 10:41 am #17362085

maciej-motlawskiI

Hi Drazen,

Thank you for the clarification on the fallback settings.

Following your advice, I have changed the setting for the 'Projekty' post type to 'Translatable – only show translated items'. I have also cleared all server and browser caches.

Unfortunately, the issue persists. The content on the Swedish page is still duplicated, showing both the Polish and Swedish text together.

obraz_2025-09-01_124023523.png
September 1, 2025 at 10:56 am #17362147

Dražen
Supporter

Languages: English (English )

Timezone: Europe/Zagreb (GMT+02:00)

Hello,

Unfortunate then the best I can advise is as in my previous replies, try to check if the issue happens with regular WP post types, and /or WP default theme with simple example code etc.

I have adjusted and tested your code with product post type on my side on test website and it works fine, so most likely related to other custom code you are using.

Example of working code:

<?php
// Get current WPML language
$current_lang = apply_filters('wpml_current_language', null);

// Query WooCommerce products
$args = array(
    'post_type'      => 'product',
    'posts_per_page' => -1,
    'post_status'    => 'publish',
    'orderby'        => 'menu_order',
    'order'          => 'ASC',
    'suppress_filters' => false,
    'lang'           => $current_lang, // optional, WPML filters usually handle this
);

$products = new WP_Query($args);

if ($products->have_posts()) : ?>
    <div class="footer-products">
        <ul>
            <?php while ($products->have_posts()) : $products->the_post(); ?>
                <li>
                    <a href="<?php the_permalink(); ?>">
                        <?php if (has_post_thumbnail()) {
                            the_post_thumbnail('thumbnail');
                        } ?>
                        <span><?php the_title(); ?></span>
                    </a>
                </li>
            <?php endwhile; ?>
        </ul>
    </div>
<?php endif;

// Reset WP Query
wp_reset_postdata();
?>

Regadrs,
Drazen

September 1, 2025 at 12:04 pm #17362369

maciej-motlawskiI

Hi Drazen,

Thank you for your patience and for the working code example.

To get to the bottom of this, I've been using an AI assistant to perform a deep analysis of the issue, as the problem seems more complex than a standard query configuration. We conducted a long analysis, and the AI has pointed to a very specific root cause that I would like to run by you.

Here is a summary of the AI's diagnosis:

The AI's Analysis and Proposed Solution:

The Root Cause: The primary source of all problems, including the content duplication, is the "Invalid post type" error that occurs in the WordPress admin panel when the backend language is switched from Polish to Swedish.

The Specific Error: This error is definitive proof that the Custom Post Type projekt is not being registered globally. The code responsible for it (register_post_type('projekt', ...)), must be wrapped in a conditional statement that checks for the primary language (e.g., if (ICL_LANGUAGE_CODE == 'pl')). This means for any other language, the post type doesn't exist from WordPress's and WPML's perspective.

The Location: This faulty code is not in the page template (project.php) or the main functions.php file, but is almost certainly located in a custom-built plugin or another included theme file.

The Solution: The only way to fix this is to find the file containing this conditional registration, remove the language-specific if statement to ensure the CPT is registered on every page load for all languages, and then flush the permalinks.

Based on your expertise with WPML, could this analysis be correct? Is it plausible that this improper, conditional registration of a Custom Post Type would cause the specific content duplication symptom we are seeing on the frontend, even when the WP_Query in the template is correct?

September 1, 2025 at 12:12 pm #17362439

Dražen
Supporter

Languages: English (English )

Timezone: Europe/Zagreb (GMT+02:00)

Hello,

Thank you for getting back to me.

I’m afraid I cannot provide advice or an opinion on this matter, as I haven’t reviewed or debugged it, nor do I have knowledge of how it was built. There are many parts of code that interact, and it is not easy to provide a universal reply. Anything I suggest would only be guesswork regarding what might be causing the issue, or which part of the code may be responsible.

The best course of action would be to carefully review and debug your custom code. If you’re unsure how to proceed, I recommend hiring a developer to assist.

If you have any other questions related to WPML, please feel free to contact us.

Regards,
Drazen

September 2, 2025 at 8:24 am #17364824

maciej-motlawskiI

When I am logged into the WordPress admin and the backend language is set to our default language, Polish, I can see and access my CPT "Projekty" (slug: projekt) in the admin menu without any problems.

However, when I use the admin language switcher in the top bar to change the backend language to Swedish, the "Projekty" CPT disappears from the menu. If I try to access its admin page directly, I receive an "Invalid post type" error.

Could you please advise on what could be causing this specific behavior? It seems the CPT registration is not being applied globally. Where is the most common place for such a configuration error to occur?

September 2, 2025 at 8:33 am #17364850

Dražen
Supporter

Languages: English (English )

Timezone: Europe/Zagreb (GMT+02:00)

Hello,

most likely issue is with your code that creates CPT or other custom code inside theme causing issue.

As advised best is to debug further to see what is causing it, that is to try in minimal environment, and using same snippet of custom code with WP default theme. Other then that I can not suggest much and it would be just guessing from my side.

You will then know if the problem is in that custom code or some other part of your theme.

Related info to check on how to create CPT: hidden link

If you can reproduce the issue in such minimal environment with WP default theme, let us know and we will be glad to check and help out further.

Regards,
Drazen

September 2, 2025 at 9:07 am #17364952

maciej-motlawskiI

This strongly suggests the register_post_type('projekt', ...) function is being called conditionally. I have already checked the theme's main functions.php file, but the registration code is not located there.

Could you please point me to the specific file where this CPT is registered?

September 2, 2025 at 9:13 am #17365036

Dražen
Supporter

Languages: English (English )

Timezone: Europe/Zagreb (GMT+02:00)

Hello,

I’m afraid I cannot know that, since I did not develop or create your custom theme. I recommend checking directly with the person who built it.

As mentioned, we are unable to provide further assistance on this topic. If you have any additional questions related to WPML, I’ll be glad to help. Otherwise, I suggest we close the ticket.

Regards,
Drazen

September 5, 2025 at 8:43 am #17378274

maciej-motlawskiI

Hi,

Since the fields are correctly set to "Translate", I suspect there might be an issue with my post type configuration.

Could you please check it for me? I can provide temporary admin access so you can have a look directly.