Skip Navigation

[Resolved] Dropdown with WPML

This support ticket is created 2 years, 10 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

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

Supporter timezone: Asia/Hong_Kong (GMT+08:00)

This topic contains 1 reply, has 2 voices.

Last updated by Luo Yang 2 years, 10 months ago.

Assisted by: Luo Yang.

Author
Posts
#2074213

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

#2074387

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.

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.