User Meta Functions
When a field group is set to User Meta type, use these three helper functions to read, write, and delete field values on WordPress user profiles.
onemeta_get_user_meta()
Retrieve a field value for a user.
php
onemeta_get_user_meta( int $user_id, string $key, mixed $default = '' ): mixed
| Parameter | Type | Description |
|---|---|---|
$user_id | int | The user ID. |
$key | string | The field key, without the onemeta_ prefix. |
$default | mixed | Value to return if no value has been saved. Default: ''. |
Returns: The saved field value, or $default if never saved.
php
// Get the current user's field value
$bio = onemeta_get_user_meta( get_current_user_id(), 'custom_bio' );
// Get a specific user's field value
$bio = onemeta_get_user_meta( 5, 'custom_bio' );
// On an author archive page
$author_id = get_queried_object_id();
$bio = onemeta_get_user_meta( $author_id, 'custom_bio' );
// With a default fallback
$bio = onemeta_get_user_meta( $author_id, 'custom_bio', 'No bio available.' );
onemeta_update_user_meta()
Save or update a field value for a user.
php
onemeta_update_user_meta( int $user_id, string $key, mixed $value ): bool|int
| Parameter | Type | Description |
|---|---|---|
$user_id | int | The user ID. |
$key | string | The field key, without the onemeta_ prefix. |
$value | mixed | The value to save. |
Returns: Meta ID on first insert, true on update, false on failure.
php
onemeta_update_user_meta( get_current_user_id(), 'custom_bio', 'Designer and developer.' );
onemeta_delete_user_meta()
Delete a saved field value from a user.
php
onemeta_delete_user_meta( int $user_id, string $key ): bool
| Parameter | Type | Description |
|---|---|---|
$user_id | int | The user ID. |
$key | string | The field key, without the onemeta_ prefix. |
Returns: true on success, false on failure.
php
onemeta_delete_user_meta( get_current_user_id(), 'custom_bio' );
Template Example — Author Archive
php
<?php
// author.php
$author_id = get_queried_object_id();
$custom_bio = onemeta_get_user_meta( $author_id, 'custom_bio' );
$avatar_id = onemeta_get_user_meta( $author_id, 'profile_photo' );
$skills = onemeta_get_user_meta( $author_id, 'skills' );
?>
<div class="author-profile">
<?php if ( ! empty( $avatar_id ) ) : ?>
<?php echo wp_get_attachment_image( $avatar_id, 'thumbnail', false, [
'class' => 'author-avatar',
'alt' => esc_attr( get_the_author_meta( 'display_name', $author_id ) ),
] ); ?>
<?php endif; ?>
<?php if ( ! empty( $custom_bio ) ) : ?>
<div class="author-bio">
<?php echo wp_kses_post( wpautop( $custom_bio ) ); ?>
</div>
<?php endif; ?>
<?php if ( is_array( $skills ) && ! empty( $skills ) ) : ?>
<ul class="author-skills">
<?php foreach ( $skills as $skill ) : ?>
<li><?php echo esc_html( $skill ); ?></li>
<?php endforeach; ?>
</ul>
<?php endif; ?>
</div>