Skip Navigation

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.

Sun Mon Tue Wed Thu Fri Sat
- 13:00 – 18:00 13:00 – 18:00 13:00 – 18:00 13:00 – 18:00 13:00 – 18:00 -
- 19:00 – 22:00 19:00 – 22:00 19:00 – 22:00 19:00 – 22:00 19:00 – 22:00 -

Supporter timezone: Asia/Kathmandu (GMT+05:45)

Tagged: 

This topic contains 10 replies, has 3 voices.

Last updated by Long Nguyen 1 year, 1 month ago.

Assisted by: Subash Chandra Poudel.

Author Posts
May 11, 2023 at 9:40 am #13628671

vanessaS-12

so I've got a weird error (again) with WPML, when trying to list my posts using WP_Query

May 11, 2023 at 12:59 pm #13630561

Subash Chandra Poudel

Hi there,

To troubleshoot the issue further I setup a Sandbox site for you which you can login to using the next link:

hidden link

Can you please upload your custom theme or code to the site, and also setup WPML and add a few posts so as to try to replicate the issue there and see how it goes?

if the issue is replicated please let me know the location of your custom code to pull the posts along with the URL/steps for me to see/check the issue.

Regards,
Subash

May 11, 2023 at 2:21 pm #13631155

vanessaS-12

thank you for the sandbox installation!

I could paste my code in functions.php and create a test blog article and translation (in french)
Important premise: In WPML settings I set up posts as "translatable - use translation if available or fallback to default language".

So then i created a custom shortcode "blog_list" listing simply the posts on hidden link and works great on EN and FR as long as the translations are published.

but look what happens if I set up the french translation as draft again: I'm navigating on the blog page (FR version) here: hidden link and the list shows a blog post "blog post EN 1" which is correct, but the permalink points to hidden link which is incorrect (if accessed as logged out, will give a 404).
This is exactly my problem!
is this a bug or am I missing something?

thanks
kind regards

May 13, 2023 at 2:37 pm #13641161

Subash Chandra Poudel

Hi there,

Thank you for the details and your efforts in setting up the WPML sandbox site.

I can see and replicate the issue on any site, not only with your custom short code but even with the default WordPress blog page.

I have escalated the issue to our team for further investigation, we will let you know here as soon as we have an update.

Regards,
Subash

May 18, 2023 at 11:18 am #13671265

Subash Chandra Poudel

Hi there,

The issue has now been confirmed and escalated to our development team. In the mean time can you please try the following workaround and see if it fixes the issue:

- Backup the site completely to prevent any issues.

- edit the file: \wp-content\plugins\sitepress-multilingual-cms\classes\core-abstract-classes\class-wpml-element-translation.php in your WordPress directory.

- Find the following code in line 293-318 of the file

private function populate_cache( $elements ) {
		if ( ! $elements ) {
			return;
		}
		$element_ids = array();
		foreach ( $elements as $element ) {
			$element_id                    = $element['element_id'];
			$language_code                 = $element['language_code'];
			$element_ids[ $language_code ] = $element_id;

			$this->element_data[ $element_id ] = array(
				'translation_id' => $element['translation_id'],
				'trid'           => $element['trid'],
				'lang'           => $language_code,
				'source_lang'    => $element['source_language_code'],
				'type'           => substr( $element['element_type'], $this->type_prefix_length ),
			);

			$this->translation_ids_element[ $element['translation_id'] ] = $element_id;
		}
		foreach ( $element_ids as $element_id ) {
			$trid                              = $this->element_data[ $element_id ]['trid'];
			$this->trid_groups[ $trid ]        = $element_ids;
			$this->translations[ $element_id ] = &$this->trid_groups[ $trid ];
		}
	}

- And replace it with:

private function populate_cache( $elements ) {
		if ( ! $elements ) {
			return;
		}

		$element_ids = array();
		foreach ( $elements as $key => $element ) {
			if (get_post_status($element["element_id"]) == "draft" || get_post_status($element["translation_id"]) == "draft") {
				unset ($elements[$key]);
				continue;
			}
			$element_id                    = $element['element_id'];
			$language_code                 = $element['language_code'];
			$element_ids[ $language_code ] = $element_id;

			$this->element_data[ $element_id ] = array(
				'translation_id' => $element['translation_id'],
				'trid'           => $element['trid'],
				'lang'           => $language_code,
				'source_lang'    => $element['source_language_code'],
				'type'           => substr( $element['element_type'], $this->type_prefix_length ),
			);

			$this->translation_ids_element[ $element['translation_id'] ] = $element_id;
		}
		foreach ( $element_ids as $element_id ) {
			$trid                              = $this->element_data[ $element_id ]['trid'];
			$this->trid_groups[ $trid ]        = $element_ids;
			$this->translations[ $element_id ] = &$this->trid_groups[ $trid ];
		}
	}

Regards,
Subash

May 18, 2023 at 3:11 pm #13673025

vanessaS-12

great!
this workaround seems working and fixing the issue.
I expect this fix to be added in the next release as well.
Thanks a lot!

May 19, 2023 at 11:24 am #13678697

Subash Chandra Poudel

Hi there,

Thank you for confirming that the workaround works.

The issue has been escalated to our development team and a proper fix will be available in the future release of WPML. However the fix might not be available in the immediate next release as the issue still requires more testing to find the best fix and proper testing to make sure no other features are affected with this fix. So please keep a note of this workaround and apply this again in future WPML updates till the fix is released.

I will send you an update here if we need more details or after the fix is released with WPML update.

Regards,
Subash

September 4, 2023 at 8:28 am #14334475

vanessaS-12

hello!
any news from the dev team on analyzing and fixing this bug?
I noticed that, while this quick workaround worked fine initially, now it brakes other functionalities like the language box in the sidebar, that is not appearing anymore on the edit post view, and basically I cannot add new translations to the default language.
I believe this side effect bug appeared after updating WPML as before everything seemed to work just fine.

Thanks a lot!
Kind regards

September 4, 2023 at 9:54 am #14335129

Subash Chandra Poudel

I did further tests and yes, I see when the workaround is applied the translation connection between the original and translated post is lost.

I have forwarded the results of the test to our 2'nd tier team. Let's wait for their fix.

As for the final fix, our development team is still on it and we don't have an ETA yet. I will update you here as soon as we have an update from our 2'nd tier and/or development team.

Regards,
Subash

October 13, 2023 at 8:44 am #14571043

vanessaS-12

hello!
any updates on this issue? I still got some 404 errors on my blog page because some of the posts are saved as draft.

thanks!
kind regards

October 13, 2023 at 9:38 am #14571683

Long Nguyen
Supporter

Languages: English (English )

Timezone: Asia/Ho_Chi_Minh (GMT+07:00)

Hi,

Subash is off and I will take care of this ticket. There is an update from our 2nd tier support. Please follow steps below:

- Edit the file wp-content/plugins/sitepress-multilingual-cms/classes/core-abstract-classes/class-wpml-element-translation.php

- On line 299, replace the code

if (get_post_status($element["element_id"]) == "draft" || get_post_status($element["translation_id"]) == "draft") {

with this one

if ( !is_admin() && (get_post_status($element["element_id"]) == "draft" || get_post_status($element["translation_id"]) == "draft")) {

❌ IMPORTANT: Please backup your database and website before proceeding ❌

This will fix the issue with the connection of the translation post in the admin area.

Look forward to your reply.
Thanks

The topic ‘[Closed] error trying to list my posts using WP_Query’ is closed to new replies.