0
votes

I'm a noob in programming, so I want to ask: What is the best way if I want to get other meta values by entering a meta value in wordpress?

Example, the user enters the value 12345 for the meta_key id_number, the output will be first name and last name of the user having that meta_value of id_number.

I was looking into get_user_meta(); but I don't know how to get the user_id using the meta_value, and output results from an array. Please enlighten me.

1

1 Answers

2
votes

I guess you can use the function get_users().

The usage is so simple... there is an example with all you need...

    $user = reset(
 get_users(
  array(
   'meta_key' => 'yourmetakey', 
   'meta_value' => $meta_value, //The value of meta key
   'number' => 1, //Limit 1 user returned
   'count_total' => false //This is always false
  )
 )
);

Always check the codex: https://codex.wordpress.org/Function_Reference/get_users