custom user meta psuedo relationship
-
I have implemented a custom user meta box in the form of a select field, with its option values pulled from a custom post type i’ve implemented with the Types plugin. I’m using this to simulate a one-to-one relationship. The list populates correctly, the values are updated in the database when you save the user, but the profile page always displays the uppermost field value, rather than the actual value stored in the DB.
Here is the code i have added in my functions.php:
///////////////////////// // Profile club field // ///////////////////////// add_action( 'show_user_profile', 'show_extra_profile_fields' ); add_action( 'edit_user_profile', 'show_extra_profile_fields' ); function show_extra_profile_fields( $user ) { ?> <h3>Club Affilliation</h3> <table class="form-table"> <tr> <th><label for="club-affilliation">Club</label></th> <td> <select name="club-affilliation" id="club-affilliation" > <option value="none">No Affilliation</option> <?php $args = array( 'post_type' => 'club', 'post_status' => 'publish', 'suppress_filters' => true ); $posts_array = get_posts( $args ); foreach ( $posts_array as $post ) : setup_postdata( $post ); ?> <option value="<?php echo $post->post_title; ?>"> <?php echo $post->post_title; ?> </option> <?php endforeach; wp_reset_postdata(); ?> </select> </td> </tr> </table> <?php } add_action( 'personal_options_update', 'save_extra_profile_fields' ); add_action( 'edit_user_profile_update', 'save_extra_profile_fields' ); function save_extra_profile_fields( $user_id ) { if ( !current_user_can( 'edit_user', $user_id ) ) return false; update_usermeta( $user_id, 'club-affilliation', $_POST['club-affilliation'] ); }
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
- The topic ‘custom user meta psuedo relationship’ is closed to new replies.