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
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
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
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.
Hi Waqar,
thanks for support.
This function works with the voice translated with WPML?
Regards
Yes, this approach should be compatible with the WPML translations.