Zum Inhalt springen Zur Seitenleiste springen

Dies ist das technische Support-Forum für WPML – das mehrsprachige WordPress-Plugin.

Mitlesen können alle, doch nur WPML-Kunden können hier Fragen veröffentlichen. Das WPML-Team antwortet im Forum an 6 Tagen pro Woche, 22 Stunden am Tag.

Sun Mon Tue Wed Thu Fri Sat
- 8:00 – 13:00 9:00 – 13:00 9:00 – 13:00 8:00 – 12:00 8:00 – 12:00 -
- 14:00 – 17:00 14:00 – 18:00 14:00 – 18:00 13:00 – 17:00 13:00 – 17:00 -

Zeitzone des Supporters: Europe/Zagreb (GMT+02:00)

Schlagwörter: 

Dieses Thema enthält 2 Antworten, hat 2 Stimmen.

Zuletzt aktualisiert von Bruno Kos Vor 1 Jahr, 3 Monaten.

Assistiert von: Bruno Kos.

Autor Beiträge
März 28, 2024 um 8:02 pm #15462523

danielM-3

Hi,

i'm using the latest versions of WordPress, WPML, Elasticpress and WPML Elasticpress. I have several custom queries (get_posts()) with the "ep_integrate" parameter in order to run the query through Elasticsearch.

While content in the main language (DE) is queried correctly, content the the secondary language (EN) does not return any results. I've run the Elasticpress indexer and there's an DE and EN index, no errors while syncing.

Does WPML elasticpress support the ep_integrate parameter?

März 28, 2024 um 8:27 pm #15462565

danielM-3

I think i just solved the problem with this filter:

add_filter( 'ep_index_name', function ( $index ) {
if( !is_admin() && defined( 'ICL_LANGUAGE_CODE' ) ) {
if( ICL_LANGUAGE_CODE == 'en' ) {
$index = 'wpwifoacat-post-1-en';
}
}

return $index;
} );

But i'm wondering why that custom code is necessary?

März 29, 2024 um 8:26 am #15463333

Bruno Kos
WPML-Unterstützer seit 12/2018

Sprachen: Englisch (English ) Deutsch (Deutsch ) Französisch (Français )

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

Hi,

Thank you for contacting WPML support!

In my opinion "WPML ElasticPress" should handle this automatically, mapping WPML's current language to the correct ElasticPress index without additional code.

Other than that I don't have more info about ep_integrate so I would need to check this with our 2nd tier.

I am wondering if something like this would help though?

add_filter('ep_formatted_args', function($formatted_args, $args) {
    // Retrieve the current language code using WPML's recommended method
    $current_language = apply_filters('wpml_current_language', NULL);

    if ($current_language) {
        // Construct the index name dynamically based on the current language
        // Assuming a naming convention like 'your_prefix-post-1-<language_code>'
        $index_prefix = 'your_prefix-post-1'; // Adjust this prefix according to your actual index naming convention
        $language_code = $current_language; // Use the WPML function to get the current language code

        // Check if the current language is English
        if ($language_code === 'en') {
            // Construct the full index name for English content
            $english_index = $index_prefix . '-' . $language_code;
            // Update the query to use the dynamically constructed English index name
            $formatted_args['index'] = $english_index;
        }

        // Extend this logic for other languages as needed
    }
    return $formatted_args;
}, 10, 2);

Remember to replace 'your_prefix-post-1' with the actual prefix used in your Elasticsearch index names. This strategy ensures that all queries going through ElasticPress will automatically target the correct index for English content based on the current WPML language setting, without needing to specify exact index names in your code.

Regards,
Bruno Kos

Das Thema „[Geschlossen] WPML Elasticpress: No posts found for EN index“ ist für neue Antworten geschlossen.