Hi, I use this function to populate a select field from a CPT
// Create dropdown of locations
add_filter( 'wpt_field_options', 'populate_locations_dropdown', 10, 3);
function populate_locations_dropdown( $options, $title, $type ){
switch( $title ){
case 'Trial Location':
$options = array(
array(
'#value' => '',
'#title' => '',
)
);
$args = array(
'post_type' => 'location',
'post_status' => 'publish',
'posts_per_page' => -1,
'suppress_filters' => 0,
'orderby' => 'title',
'order' => 'ASC'
);
$posts_array = get_posts( $args );
foreach ($posts_array as $post) {
$options[] = array(
'#value' => $post->ID,
'#title' => $post->post_title . ' - ' . get_post_meta($post->ID, 'wpcf-laboratory-locality', true)
);
}
break;
}
return $options;
}
But when I save the form, the custom field is saved only in the current language.
When I switch to another language the field is blank.
If I remove the "suppress_filter=>0" parameter it works, but the dropdown list contains multiple entries in different languages.
What I am doing wrong?
Thanks
Hello,
I have searched it in WPML forum, and found this thread:
https://wpml.org/forums/topic/fetch-posts-by-language/
See the solution of above thread:
Check the WPML setting for the custom post type under WPML → Settings → Post Types Translation: for the query to work it needs to be set to "Translatable - only show translated items".
For your reference.