WordPress.org

Ready to get started?Download WordPress

Forums

Displaying custom usermeta fields on a page (2 posts)

  1. aeboi80
    Member
    Posted 1 year ago #

    I have added several custom usermeta fields to the user profile within the WP admin. I have a page with the slug of pm2. The current author of page pm2 username is demo

    I am trying to display the values of the custom usermeta fields of the author on this page.

    Here is the code I added to my functions.php file to register the custom usermeta fields:

    function fb_add_custom_user_profile_fields( $user ) {
        ?>
    	    <h3><?php _e('Extra Profile Information', 'your_textdomain'); ?></h3>
    	    <table class="form-table">
    
    	    	<tr>
    	    		<th>
    	    			<label for="phone_number"><?php _e('Phone Number', 'your_textdomain'); ?></label>
    	    		</th>
    	    		<td>
    	    			<input type="text" name="phone_number" id="phone_number" value="<?php echo esc_attr( get_the_author_meta( 'phone_number', $user->ID ) ); ?>" class="regular-text" /><br />
    	    			<span class="description"><?php _e('Please enter your phone number.', 'your_textdomain'); ?></span>
    	    		</td>
    	    	</tr>
    
    	    	<tr>
    	    		<th>
    	    			<label for="skype_name"><?php _e('Skype Name', 'your_textdomain'); ?></label>
    	    		</th>
    	    		<td>
    	    			<input type="text" name="skype_name" id="skype_name" value="<?php echo esc_attr( get_the_author_meta( 'skype_name', $user->ID ) ); ?>" class="regular-text" /><br />
    	    			<span class="description"><?php _e('Please enter your Skype Name.', 'your_textdomain'); ?></span>
    	    		</td>
    	    	</tr>
    
    	    	<tr>
    	    		<th>
    	    			<label for="on_fire_aff_link"><?php _e('On Fire Affiliate Link', 'your_textdomain'); ?></label>
    	    		</th>
    	    		<td>
    	    			<input type="text" name="on_fire_aff_link" id="on_fire_aff_link" value="<?php echo esc_attr( get_the_author_meta( 'on_fire_aff_link', $user->ID ) ); ?>" class="regular-text" /><br />
    	    			<span class="description"><?php _e('Please enter your On Fire Affiliate link.', 'your_textdomain'); ?></span>
    	    		</td>
    	    	</tr>
    
    	    </table>
        <?php }
        function fb_save_custom_user_profile_fields( $user_id ) {
        	if ( !current_user_can( 'edit_user', $user_id ) )
        		return FALSE;
        		update_usermeta( $user_id, 'phone_number', $_POST['phone_number'] );
        		update_usermeta( $user_id, 'skype_name', $_POST['skype_name'] );
        		update_usermeta( $user_id, 'on_fire_aff_link', $_POST['on_fire_aff_link'] );
        	}
        add_action( 'show_user_profile', 'fb_add_custom_user_profile_fields' );
        add_action( 'edit_user_profile', 'fb_add_custom_user_profile_fields' );
        add_action( 'personal_options_update', 'fb_save_custom_user_profile_fields' );
        add_action( 'edit_user_profile_update', 'fb_save_custom_user_profile_fields' );

    If I want to display the value store within the author's usermeta field of skype_name on the page with the slug pm2 how do I do that?

    I tried using the following but it didn't work:

    $author_skype_name = get_user_meta('skype_name', true);
    echo $author_skype_name;

    but that didn't work.

    Some help here would be appreciated :-)

    Additionally I forgot to mention. I am trying to do this OUTSIDE of the wordpress loop too.

  2. aeboi80
    Member
    Posted 1 year ago #

    Additionally I forgot to mention. I am trying to do this OUTSIDE of the wordpress loop too.

Topic Closed

This topic has been closed to new replies.

About this Topic