Hi @polymathy
How do you add the custom fields to your Account form? Could you share the code so we can review why it returns the number instead of the text?
Regards,
Hi @champsupertramp,
I use this code (the code from my first post is the wrong part of the code): I just create a field in the form editor called “therapy_center” (metakey) and then I add the field with said code:
/**
* Add extra fields to user account tab
*/
function showUMExtraFields()
{
$id = um_user('ID');
$output = '';
$names = array('si_gender', 'therapy_center');
$fields = array();
foreach ($names as $name)
$fields[$name] = UM()->builtin()->get_specific_field($name);
$fields = apply_filters('um_account_secure_fields', $fields, $id);
foreach ($fields as $key => $data)
$output .= UM()->fields()->edit_field($key, $data);
echo $output;
}
add_action('um_after_account_general', 'showUMExtraFields', 100);
/**
* Get content for extra fields in user account tab
*/
function getUMFormData()
{
$id = um_user('ID');
$names = array('si_gender', 'therapy_center');
foreach ($names as $name)
update_user_meta($id, $name, $_POST[$name]);
}
add_action('um_account_pre_update_profile', 'getUMFormData', 100);
The code hooks into two filters, that the Ultimate Member plugin provides, um_after_account_general and um_account_pre_update_profile.
Hi @polymathy
And how do you add the select options? is it via Field settings?
You will need to retrieve the field settings so that you can match the select values with the selected one so you can retrieve the option name for you to save in the user meta.
Regards,
For some reason, the select options in the HTML of the account form only have numerical values, like this:
<option value="0" data-select2-id="16">City</option>
While in the registration, it looks like this:
<option value="City" data-select2-id="14">City</option>
The output from the account form is generated by the UM method “edit_field”. I just give it the $data array related to the field (as you can see in my code), which looks correct to me, especially since it correctly identifies the field as “select” type:
krumo($data); (Array, 9 elements)
type (String, 6 characters ) select
title (String, 15 characters ) Therapiezentrum
metakey (String, 14 characters ) therapy_center
options (Array, 5 elements)
visibility (String, 3 characters ) all
label (String, 15 characters ) Therapiezentrum
public (String, 1 characters ) 1
required (String, 1 characters ) 1
editable (String, 1 characters ) 1
I don’t know what the edit_field method does inside. It’s several hundred lines of code, but it returns the HTML code with the value as numbers instead of the actual values.
Do I have to pass the edit_field method anything else other than $key and $data in order for the values to be correct?
Hi @polymathy
Could you please try the following code if this will change the option values?
Please try each code at a time just to see if this swaps the values:
add_filter("um_fields_options_enable_pairs__<insert the field key here>", "__return_true" );
Or
add_filter("um_fields_options_enable_pairs__<insert the field key here>", "__return_false" );
You can add it to your theme’s functions.php or via the code snippet plugin.
Feel free to re-open this thread by marking this topic as “Not Resolved” so we can get back to you.
Regards,
Hi @champsupertramp,
I tried both codes, but they didn’t change the option values. The only thing that seemingly did change was the data-select2-id attribute and there it was only the actual IDs that changed. But the values remained completely untouched by this.
Any other idea, what the problem could be?
I still can’t get this to work properly. Any idea what the problem is here?