Skip Navigation

[Resolved] add multiple select options with same value

This support ticket is created 5 years, 3 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/Karachi (GMT+05:00)

This topic contains 1 reply, has 2 voices.

Last updated by Waqar 5 years, 3 months ago.

Assisted by: Waqar.

Author
Posts
#1184036

Tell us what you are trying to do?
Add "United States" twice in a country drop-down select (once at the top and once alphabetically)

Is there any documentation that you are following?
I don't know

Is there a similar example that we can see?
hidden link (top list)

What is the link to your site?
hidden link

#1184075

Waqar
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

Hi Jason,

Following up on our earlier discussion, you can also use "wpt_field_options" filter, to find the select option for "United States" and add its duplicate on top:


add_filter( 'wpt_field_options', 'func_to_duplicate_us_option', 10, 3);
function func_to_duplicate_us_option( $options, $title, $type ){
	if ($title == "test") {

			$find = "us";
			$options_temp_default = $options[0];

			for ($i=1; $i < count($options) ; $i++) { 
			
				$options_new[] = $options[$i];
				if( $options[$i]['#value'] == $find) {
					$options_temp_req = $options[$i];
				}
			}

			array_unshift($options_new, $options_temp_req);
			array_unshift($options_new, $options_temp_default);

			$options = $options_new;
	}
	return $options;
}

The above code can be added in active theme's "functions.php" file and you'll replace "test" with the actual "Field name" set for the relevant custom field, in the settings.
( example screenshot: hidden link )

note: To make this function work for more than one select fields, you can update the line:


if ($title == "test") {

To:


if ( ($title == "test") || ($title == "test1") ) {

regards,
Waqar

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