Skip Navigation

[Resolved] Dynamic selection menu multilanguage

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 5 replies, has 2 voices.

Last updated by Waqar 1 year, 9 months ago.

Assisted by: Waqar.

Author
Posts
#2558189

Hi,
i reconnect to ticket https://toolset.com/forums/topic/dynamic-selection-menu/.
The solution includes creating a dedicated custom post type but I would have to copy the content from an already active select menu. How can I do that?
Regards

#2558591

Hi,

Thank you for contacting us and I'd be happy to assist.

> The solution includes creating a dedicated custom post type but I would have to copy the content from an already active select menu. How can I do that?

- I'm afraid, I couldn't fully understand the requirement around the 'already active select menu'. Can you please share some more details? I'll be in a better position to suggest the next steps, accordingly.

regards,
Waqar

#2558593

Hi, Waqar
Of course!!!

I have a custom post type with different sections (example "Persona 1", "Persona 2" etc).
Into "Persona 1" I have a nationality field with different entries (these are also translated into the different languages).
Now I should create the nationality field for the other groups (Persona 2 etc..) as well.

I would like to automatically insert all the entries into "Persona 1" -> "nationality" into "Persona x" -> "nationality" so that if I change the parent selection menu the others will also change.

The whole thing has to work with WPML.

I hope I have been exhaustive.

In case let me know!

Regards

#2559253

Thank you for sharing these details.

If you've added the options for the one select type custom field with slug 'persona-1' and would like to use the same options for the other select fields with titles e.g. 'Persona 2', 'Persona 3', 'Persona 4' etc, the code for the 'wpt_field_options' filtering function would look like this:


add_filter( 'wpt_field_options', 'custom_populate_select_field_options', 10, 3);
function custom_populate_select_field_options( $options, $title, $type ){
	$target_source_field = 'persona-1';
	switch( $title ){
		case 'Persona 2':
		case 'Persona 3':
		case 'Persona 4':
		$fields = get_option('wpcf-fields');
		
		$target_options = $fields[$target_source_field]['data']['options'];
		if(!empty($target_options)){
			foreach ($target_options as $target_options_item) {
				if(is_array($target_options_item)) {
					$options[] = array(
						'#value' => $target_options_item['value'],
						'#title' => $target_options_item['title'],
					);
				}		
			}
		}	
		break;
	}
	return $options;
}

You'll update the custom field slugs and the custom field titles in this snippet, as used on your website.

I hope this helps and let me know how it goes.

#2559567

Hi Waqar,
thanks for support.
This function works with the voice translated with WPML?
Regards

#2562237

Yes, this approach should be compatible with the WPML translations.