Advertisements

get_usermeta

Definition:
function get_usermeta( $user_id, $meta_key = '' ) {}

Retrieve user metadata.
If $user_id is not a number, then the function will fail over with a ‘false’ boolean return value. Other returned values depend on whether there is only one item to be returned, which be that single item type. If there is more than one metadata value, then it will be list of metadata values.

Parameters

  • int $user_id: User ID
  • string $meta_key: Optional. Metadata key.

Source code

function get_usermeta( $user_id, $meta_key = '' ) {

	_deprecated_function( __FUNCTION__, '3.0', 'get_user_meta()' );

	global $wpdb;

	$user_id = (int) $user_id;



	if ( !$user_id )

		return false;



	if ( !empty($meta_key) ) {

		$meta_key = preg_replace('|[^a-z0-9_]|i', '', $meta_key);

		$user = wp_cache_get($user_id, 'users');

		// Check the cached user object

		if ( false !== $user && isset($user->$meta_key) )

			$metas = array($user->$meta_key);

		else

			$metas = $wpdb->get_col( $wpdb->prepare("SELECT meta_value FROM $wpdb->usermeta WHERE user_id = %d AND meta_key = %s", $user_id, $meta_key) );

	} else {

		$metas = $wpdb->get_col( $wpdb->prepare("SELECT meta_value FROM $wpdb->usermeta WHERE user_id = %d", $user_id) );

	}



	if ( empty($metas) ) {

		if ( empty($meta_key) )

			return array();

		else

			return '';

	}



	$metas = array_map('maybe_unserialize', $metas);



	if ( count($metas) == 1 )

		return $metas[0];

	else

		return $metas;

}

1881

Advertisements

2 Responses to “get_usermeta”

  1. hi 🙂
    i use get_user_meta, but this function return null o false, but in my mysql There are data

    help please

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: