Skip Navigation

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

Problem:
I'm using a custom code, I want to display the translation posts in the second language and fallback posts in the original language if the translations are missing with a custom query and Ajax.
Solution:
Add the code below before the WP_Query in the Ajax callback function to show the fallback posts:

if ( class_exists( 'WPML_Display_As_Translated_Tax_Query' ) ) {
    global $sitepress, $wpml_term_translations;
    $wpml_display_as_translated_tax = new WPML_Display_As_Translated_Tax_Query( $sitepress, $wpml_term_translations );
    $wpml_display_as_translated_tax->add_hooks();
}

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 2 voices.

Last updated by Long Nguyen 1 year, 2 months ago.

Assisted by: Long Nguyen.

Author Posts
December 20, 2023 at 7:04 am #15098171

Long Nguyen
Supporter

Languages: English (English )

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

Hi,

I got a workaround from our 2nd tier support to fix this issue. You can add the code below before WP_Query in the Ajax callback function to show the fallback posts. I test it on my end and it works correctly.

if (class_exists('WPML_Display_As_Translated_Tax_Query')) {
	global $sitepress, $wpml_term_translations;
	$wpml_display_as_translated_tax = new WPML_Display_As_Translated_Tax_Query( $sitepress, $wpml_term_translations );
	$wpml_display_as_translated_tax->add_hooks();
}

Look forward to your reply.
Thanks

December 21, 2023 at 3:15 pm #15111671

Gregory

Hi there,

Thank you very much for your reply and for sending a workaround.
We are still need to run some tests to verify that this works in various cases, but we'll mark this as solved for now.
It would be great if this issue got properly resolved, as we still consider it a serious problem that expected functionality is not kept when using AJAX.

Kind regards