Hi can anyone help me to save the post title selected in this select box? I would like to let people select posts out of a dropdown select box and save the value to their profile.
Help is very appreciated!
add_action( 'show_user_profile', 'product_selection_field', 5 );
add_action( 'edit_user_profile', 'product_selection_field', 5 );
function product_selection_field( $user ) {
$args = array( 'post_type' => 'product', 'product_tag' => 'partner' );
$products = get_posts( $args );
foreach ( $products as $page ) {
if ( strtolower($product_name) == $page ) {
$role_option .= "<option value='".strtolower($page->post_title)."' selected='selected'>";
$currentrole = strtolower($role_name);
} else {
$product_option .= "<option value='".strtolower($page->post_title)."'>";
}
$product_option .= $page->post_title;
$product_option .= "</option>";
}
?>
<div class="form-group full-width">
<label for="club_choice"><?php _e("Select your club"); ?></label>
<select name="club_choice" id="club_choice" class="input">
<?php
echo $product_option;
?>
</select>
</div>
<?php
}
// then I save the field
add_action('user_register','adding_extra_reg_fields');
function adding_extra_reg_fields($user_id) {
if ( !empty( $_POST['club_choice'] ) )
update_user_meta( $user_id, 'club_choice', $_POST['club_choice'] );
}