# get Insert id for meta field

I'm in a situation where i also need to get the id of the inserted meta( meta_id for post meta and umeta_id for user meta)

For eg i add a user meta

add_user_meta($user_id,'some_key',$some_value,false);


is there a built in method of getting the umeta_id for this meta field without using custom query?

Same case for retrieving meta value with meta id. I had to use this

$sql_query = 'select umeta_id as my_key_id, meta_value from wp_usermeta where user_id = "'.$user_id.'" and meta_key = "some_key" order by my_key_id asc';


Any better alternative?

-

You don't need to do anything special here since 3.3, because add_user_meta() returns the meta ID:
$meta_id = add_user_meta($user_id, 'some_key', $some_value, false );  - $wpdb->insert_id was the simple solution.
global $wpdb; add_user_meta($user_id,'some_key',$some_value,false);$new_meta_key_id = $wpdb->insert_id;  - Can you show us a better example of the solution? – Brian Fegter Oct 9 '12 at 10:04 No need to get Insert id for meta field.You get key value by using this function. $user_some_value = get_user_meta( $user_id, some_key );  - I'm aware this is how we obtain value BUT sorry this is NOT what i need – Dipesh Kc Oct 8 '12 at 6:17 ok.You can get last insert id$lastid = \$wpdb->insert_id; –  dipali Oct 8 '12 at 6:24