I have a registration form and a profile update form that I created a custom field with dropdown in. When the user selects the correct name and saves the data, it inserts the row ID instead of the name. IE:
Club 1
Club 2
Club 3
Club 4
If a user selects club 2, it inserts into meta "1" instead of "Club 2"
In the user update form I have it setup the way Ultimate members says in their documentation.
*DB Entry *enter image description here
The custom callback in functions.php per documentation
function ClubCallback() {
global $wpdb; // WordPress database access abstraction layer
// Table name assuming the table structure holds club names
$table_name = $wpdb->prefix . 'wp_Club';
// Query to select club names from the database
$query = "SELECT ClubNames FROM $table_name";
// Retrieving data from the database
$results = $wpdb->get_results($query, ARRAY_A);
$club = array();
// Constructing an array of club names
foreach ($results as $row) {
$club[] = $row['Club'];
}
// Return the array of club names
return array_unique($club);
}
add_shortcode('ClubCallback', 'clubCallback');
This is what I used in their documentation
https://docs.ultimatemember.com/article/1884-custom-callback-dropdowns
// Constructing an array of club names
foreach ($results as $row) {
//$club[] = $row['club'];
$club[$row['club']][] = $row['club'];
}
I tried the above but this does not work.
How can I get the result to show the club name instead of the value of the row?
2
Answers
I was able to figure out that in the array I had to contruct it so the key was first and the value was second. Here is my updated code.