Salta la navigazione

Questo thread è stato risolto. Ecco una descrizione del problema e della soluzione.

Problem:
The client needed a solution for displaying the 'post grid' widget from correctly in a multilingual setup using WPML. The issue happens only if you switch the default language from English to another language.
Solution:
We provided a workaround to be added to the functions.php file. Here is the code that should be inserted:

// WPML Workaround for compsupp-7881<br />add_filter( 'elementor/frontend/before_render', 'wpml_compsupp7881_filter_post_grid_widget');<br /><br />function wpml_compsupp7881_filter_post_grid_widget($element) {<br />    if ( 'posts' !== $element->get_name() ) {<br />        return;<br />    }<br /><br />    $settings = $element->get_settings();<br /><br />    if ( isset( $settings['posts_include_term_ids'] ) && is_array( $settings['posts_include_term_ids'] ) ) {<br /><br />        // Query by terms<br />        foreach ( $settings['posts_include_term_ids'] as $key => $id ) {<br /><br />            $taxonomy = 'category';<br /><br />            $term = get_term($term_id);<br /><br />            if ($term instanceof WP_Term) {<br />                $taxonomy = $term->taxonomy;<br />            }<br /><br />            $id = apply_filters( 'wpml_object_id', $id, $taxonomy, true );<br /><br />            unset($settings['posts_include_term_ids'][$key]);<br />            $settings['posts_include_term_ids'][] = $id;<br /><br />        }<br /><br />        // Update the settings<br />        $element->set_settings( 'posts_include_term_ids', $settings['posts_include_term_ids'] );<br />    }<br />}

Please note that this solution might be outdated or not applicable to your specific case. If this workaround does not resolve your issue, 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 open a new support ticket at WPML support forum.

Questo è il forum di assistenza tecnica di WPML, il plug-in multilingue di WordPress.

La sua lettura è permessa a tutti, ma la pubblicazione è riservata esclusivamente ai clienti di WPML. Il team di WPML risponde sul forum 6 giorni su 7, 22 ore su 24.

Etichettato: 

Questo ticket contiene 3 risposte, ha 0 voci.

Ultimo aggiornamento da Tommaso Signori 1 mese, 1 settimana fa.

Assistito da: Laura.

Autore Messaggi
Febbraio 26, 2025 a 8:59 am #16749751

Tommaso Signori

Buonasera Laura,

ti ringrazio per il codice, ha funzionato relativamente all'elemento 'Loop Item', tuttavia non ha funzionato per l'elemento "post grid" che ti ho segnalato in seguito, puoi vedere qui un esempio: link nascosto

Anche l'elemento post grid è stato creato nella sandbox, potresti fornirmi del codice per visualizzare anche quell'elemento correttamente.

Fammi sapere se ti dovesse servire altro nella sandbox che interveniamo.

A presto e buona serata.

Febbraio 26, 2025 a 10:40 am #16750261

Tommaso Signori

Buongiorno,

ho notato che è stato creato questo ticket per risolver il problema relativo all'elemento "post grid" di Elementor.

Segnalo che nelle pagine delle categorie di prodotto non si vedono i prodotti in lingua inglese:
link nascosto
link nascosto
link nascosto
link nascosto

Nella sandbox fornita nel precedente ticket abbiamo ricreato l'elemento post grid: link nascosto, è il primo elemento visibile nella pagina.

Fatemi sapere se potete inviarmi un codice php come fatto in precedenza, grazie per il supporto e buona giornata.

Febbraio 26, 2025 a 3:42 pm #16751945

Laura
Supporter

Lingue: Inglese (English ) Italiano (Italiano )

Fuso orario: Europe/Rome (GMT+02:00)

Il ticket è al secondo livello.

Febbraio 27, 2025 a 8:43 am #16754540

Laura
Supporter

Lingue: Inglese (English ) Italiano (Italiano )

Fuso orario: Europe/Rome (GMT+02:00)

Ecco il workaround, sempre da inserire nel functions.php

// WPML Workaround for compsupp-7881
add_filter( 'elementor/frontend/before_render', 'wpml_compsupp7881_filter_post_grid_widget');

function wpml_compsupp7881_filter_post_grid_widget($element) {
	if ( 'posts' !== $element->get_name() ) {
		return;
	}

	$settings = $element->get_settings();

	if ( isset( $settings['posts_include_term_ids'] ) && is_array( $settings['posts_include_term_ids'] ) ) {

		// Query by terms
		foreach ( $settings['posts_include_term_ids'] as $key => $id ) {      

			
			$taxonomy = 'category';

			$term = get_term($term_id);			

			if ($term instanceof WP_Term) {
				$taxonomy = $term->taxonomy;
			} 

			$id = apply_filters( 'wpml_object_id', $id, $taxonomy, true );

			unset($settings['posts_include_term_ids'][$key]);
			$settings['posts_include_term_ids'][] = $id;

		}

		// Update the settings
		$element->set_settings( 'posts_include_term_ids', $settings['posts_include_term_ids'] );
	}
}
Febbraio 27, 2025 a 6:41 pm #16757736

Tommaso Signori

Buonasera Laura,

ho implementato il codice suggerito e confermo che funziona, grazie mille per il tuo supporto.

A presto e buona serata.