hello scotty501
Did you ever resolve this? I too want this function but I dont know how. Could you share how you did it?
To show the ID number of any author, paste this into the loop of a post, page or CPT of the author/user in questions.
<?php
$user = get_userdata($post->post_author);
echo the_author_meta( 'ID' )
?>
Thanks for the response Ape (great name).
Its not really an author info in a post as such I am trying to show – just want to insert some kind of membership number or any unique number for that matter into the User Profile – the user ID seemed a good place to start.
I can easily add an extra field using a plugin but all seem to be user based – where I want the number to be automatically assigned – and as USER ID is automatically assigned – it works well for the purpose – and cannot be changed – perfect. If I could get it to display as a field within the profile.
Make sense or have I just confused the world 🙂
This might work for you…
add_action( 'show_user_profile', 'extra_profile_fields' );
function extra_profile_fields( $user ) { ?>
<table class="form-table">
<tr>
<th><label>Profile/User ID</label></th>
<td>
<input type="text" name="uuid" id="uuid" value="<?php $user = get_userdata($post->post_author); echo the_author_meta( 'ID' ) ?>" class="regular-text" readonly />
</td>
</tr>
</table>
<?php }
Please note, I’ve not tested or checked the code.
Paste it into your function.php template file if you have one.
Ah man that almost worked – it placed the extra field in there – but it shows “0” in the box – instead of the true user ID – other than that – it would appear to the be right way to go – it shows “0” regardless of which user profile I look at.
If I could fix that part – I am where I want to be.
No promises, as I’ve not tested it, but you can try this…
$user = get_userdata($post->post_author);
add_action( 'show_user_profile', 'extra_profile_fields' );
function extra_profile_fields( $user ) { ?>
<table class="form-table">
<tr>
<th><label>Profile/User ID</label></th>
<td>
<input type="text" name="uuid" id="uuid" value="<?php echo esc_attr( get_the_author_meta( 'ID', $user->ID ) ) ?>" class="regular-text" readonly />
</td>
</tr>
</table>
<?php }
That worked perfectly! Thank you so much.