I have created a registration form on WPUF so that users can select their region from a taxonomy. The code is loaded on the form using an action hook. The code loads the terms from the taxonomy in a dropdown and users can select the region.
But I am having an issue saving the selected terms into the custom field on the user profile. Find the code below:
function user_region_taxonomy( $form_id, $post_id, $form_settings, $tax, $user_id ) {
$taxterms = get_terms( 'user_region', array("hide_empty" => "0"));
if ( $post_id ) {
get_post_meta( $post_id, 'user_region_location', true );
}
?>
<div class="wpuf-label">
<label>User Region</label>
</div>
<div class="wpuf-fields">
<select name='user_region_location' id='user_region_location'>
<option value='' <?php if (!count( $names )) echo "selected";?>>Select Term</option>
<?php foreach ( $taxterms as $term ) {
echo '<option name="user_region_location" value="' . $term->slug . '" selected>' . $term->name . '</option>',"\n";
} ?>
</select>
</div>
<?php
}
add_action( 'user_region_hook', 'user_region_taxonomy', 10, 3 );
function update_user_region_hook( $post_id ) {
if ( isset( $_POST['user_region_location'] ) ) {
update_post_meta( $post_id, 'user_region', $_POST['user_region_location'] );
}
}
add_action( 'wpuf_after_register', 'update_user_region_hook' );
add_action( 'wpuf_update_profile', 'update_user_region_hook' );