I found a post regarding the add extra field to the user profile page. After that i want to save the extra field to the usermeta table. Which i did by the following code.
add_action( 'personal_options_update', 'my_save_badge_profile_fields' );
add_action( 'edit_user_profile_update', 'my_save_badge_profile_fields' );
function my_save_badge_profile_fields( $user_id ) {
if ( !current_user_can( 'edit_user', $user_id ) )
return false;
/* Copy and paste this line for additional fields. Make sure to change 'twitter' to the field ID. */
update_usermeta( $user_id, 'badge', $_POST['badge'] );
}
But now i want to store an array of value to the ‘badge’ name because i added multiple check box in user profile page in admin and my code for adding more check box in user profile page is written bellow.
add_action( 'show_user_profile', 'my_show_badge_profile_fields' );
add_action( 'edit_user_profile', 'my_show_badge_profile_fields' );
function my_show_badge_profile_fields( $user ) {
?> <h3>User Badges</h3>
<table class="form-table">
<tr>
<th><label for="twitter">Badges:</label></th>
<?php
$args = array(
'post_type' => 'badge',
);
// The query itself
$sb_user_query = new WP_Query( $args );
// The loop
while ( $sb_user_query->have_posts() ) : $sb_user_query->the_post();
$badge_id = $sb_user_query->post->ID;
$badge_title = get_the_title();
$badge_image_small = get_the_post_thumbnail( $badge_id, array(16,16) );
?>
<td>
<?php echo $badge_image_small; ?> <input type="checkbox" value="<?php echo $badge_title; ?>" name="badge">
</td>
<?php
endwhile;
?>
</tr>
</table>
<?php
}
Now i want to save the data in the usermeta table in database like an array, just like the name in the check box is ‘badge’ and the value is an array like { ‘a’,’b’,’c’} .