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.

This topic contains 0 reply, has 1 voice.

Last updated by blandineR-2 7 months, 1 week ago.

Author Posts
October 21, 2024 at 8:55 am

blandineR-2

Background of the issue:
I am trying to translate a Custom Post Type (CPT) on my site hidden link using WPML and display it in an Elementor grid loop.

Symptoms:
When I translate a CPT, it is not being displayed in an Elementor grid loop.

Questions:
hidden link
When I switch to english, the translated CPT disapear from the page.
It looks like it is not being parsed by the grid loop.

October 21, 2024 at 9:25 am
October 21, 2024 at 11:43 am #16312043

blandineR-2

I was using a custom query and didn't realize that ID of the translated CPT is different from the original one.
Here is my updated custom query :

// Ajouter un filtre pour filtrer par IDs dans Elementor Pro avec support WPML
function custom_query_by_post_team( $query ) {
// Définir les IDs que tu veux filtrer dans la langue d'origine
$post_ids = array( 73053, 73072, 73245, 73149, 73195, 73035, 73058, 73141, 73065, 73140, 72962, 73138, 73027 ); // membres à afficher

// Récupérer la langue actuelle via WPML
$current_lang = apply_filters( 'wpml_current_language', null );

// Traduire les IDs des membres d'équipe dans la langue actuelle
$translated_post_ids = array_map(function($id) use ($current_lang) {
return icl_object_id($id, 'team-member', true, $current_lang); // Adapter 'team-members' à ton type de publication
}, $post_ids);

// Appliquer le filtre post__in avec les IDs traduits
if ( !empty($translated_post_ids) ) {
$query->set( 'post__in', $translated_post_ids );
$query->set( 'orderby', 'title' ); // Trier par titre (title)
$query->set( 'order', 'ASC' ); // 'ASC' pour ordre alphabétique croissant, 'DESC' pour ordre décroissant
}
}

// Appliquer ce filtre dans Elementor via le hook "elementor/query"
add_action( 'elementor/query/my_custom_team_query', 'custom_query_by_post_team' );