Issue with WordPress Adding extra user profile fields

I am having an issue with adding custom fields to the wordpress user profile and having the inputted fields show on the front of the site. Using the below tutorial I thought I had it working, however noticed that actually it only works for ONE user, then all of the others don’t work, this is what is confusing me as I am used to things either working, or not working, whereas this works for the first user I tried it for, but no others.

I have looked high and low trying different things to no avail.

Read More

My purpose for this is to allow multiple wordpress users to add their Google+ profile to the wordpress head on posts BY that specific author with the rel attribute.

Here is the tutorial I have used

http://bavotasan.com/2009/adding-extra-fields-to-the-wordpress-user-profile/

Here is the code I am using for the function

1 – This adds the field to the user profile

/* Add Additional Fields to Author Profile */

add_action( 'show_user_profile', 'my_show_extra_profile_fields' );
add_action( 'edit_user_profile', 'my_show_extra_profile_fields' );

function my_show_extra_profile_fields( $user ) { ?>

    <h3>Extra profile information</h3>

    <table class="form-table">

        <tr>
            <th><label for="u-profs">Profile Info</label></th>

            <td>
                <input type="text" name="u-profs" id="u-profs" value="<?php echo esc_attr( get_the_author_meta( 'u-profs', $user->ID ) ); ?>" class="regular-text" /><br />
                <span class="description">Enter Your Profile Info.</span>
            </td>
            <td>
                <input type="text" name="u-profs2" id="u-profs2" value="<?php echo esc_attr( get_the_author_meta( 'u-profs2', $user->ID ) ); ?>" class="regular-text" /><br />
                <span class="description">Enter Your Google+ Url.</span>
            </td>
        </tr>

    </table>
<?php }

add_action( 'personal_options_update', 'my_save_extra_profile_fields' );
add_action( 'edit_user_profile_update', 'my_save_extra_profile_fields' );

foreach($user_ids as $user_id){
    update_user_meta( $user_id, 'u-profs2', $_POST['u-profs2'] );
}

function my_save_extra_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 'u-profs' to the field ID. */
    update_user_meta( $user_id, 'u-profs', $_POST['u-profs'] );
    update_user_meta( $user_id, 'u-profs2', $_POST['u-profs2'] );
}

2 – This gets the field content and adds it to the wp_head of wordpress

    /* Google Rel Author */

function google_rel_author_in_document_head() {
echo '<link rel="author" href="' . get_the_author_meta('u-profs2') . '"/>';
}
add_action('wp_head', 'google_rel_author_in_document_head',99);

This link on StackOverflow seems to be a similar problem but is unresolved…

Multiple update_user_meta in WordPress

Related posts

Leave a Reply

1 comment

  1. Right I found the working code in the end…

    /* Add Additional Fields to Author Profile */
    
    add_action( 'show_user_profile', 'my_show_extra_profile_fields' );
    add_action( 'edit_user_profile', 'my_show_extra_profile_fields' );
    
    function my_show_extra_profile_fields( $user ) { ?>
    
        <h3>Extra profile information</h3>
    
        <table class="form-table">
    
            <tr>
                <th><label for="u-profs">Profile Info</label></th>
                <td>
                    <input type="text" name="u-profs2" id="u-profs2" value="<?php echo esc_attr( get_the_author_meta( 'u-profs2', $user->ID ) ); ?>" class="regular-text" /><br />
                    <span class="description">Enter Your Google+ Url.</span>
                </td>
            </tr>
    
        </table>
    <?php }
    
    add_action( 'personal_options_update', 'my_save_extra_profile_fields' );
    add_action( 'edit_user_profile_update', 'my_save_extra_profile_fields' );
    
    function my_save_extra_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 'u-profs' to the field ID. */
        update_user_meta( $user_id, 'u-profs2', $_POST['u-profs2'] );
    }
    
    /* Google Rel Author */
    
    function google_rel_author_in_document_head() {
    global $post;
    $author_id=$post->post_author;
    ?>
    <link rel="author" href="<?echo get_user_meta($author_id, 'u-profs2', true);?>"/>
    <?
    }
    add_action('wp_head', 'google_rel_author_in_document_head',99);