title: Wordpress - get the userID from custom user meta
body: <p>I try to get the wordpress <code>USER ID</code> from a userMeta key I created during the registration.</p>
  
  <p>The user meta key is 'lh_scuritycode' with meta value <code>$_GET["key"]</code>.</p>
  
  <p><code>$_GET["key"] = f16dea7e995b14e420ddb96fb7dbd67f</code></p>
  
  <p>This is my code:</p>
  
  <pre><code>&lt;?php
  
  if ((ctype_alnum($_GET["key"])) &amp;&amp; (strlen($_GET["key"]) == 32)) {
  
      $lh_users = get_users( array(
                      "meta_key" =&gt; "lh_scuritycode",
                      "meta_value" =&gt; $_GET["key"],
                      "number" =&gt; 1,
                      "count_total" =&gt; false
                  ) );
  
      foreach ($lh_users as $lh_user) {
          echo '&lt;li&gt;' . $lh_user-&gt;id . '&lt;/li&gt;';
      }
  
  } else {    
      echo "Der String ".$_GET["key"]." ist fehlerhaft.\n";   
  }
  
  ?&gt;
  </code></pre>
  
  <p>Now, <code>$lh_users</code> is only an array if I <code>echo</code> it. When I use the <code>foreach</code> it works. How can I do it without that <code>foreach</code>?</p>
  
  <p>when I do this "var_dump" the result is:</p>
  
  <blockquote>
    <p>array(1) { [0]=> object(WP_User)#126 (7) { ["data"]=>
    object(stdClass)#2077 (10) { ["ID"]=> string(2) "24" ["user_login"]=>
    string(7) "Aner" ["user_pass"]=> string(34) "$P$BDpMKv0"
    ["user_nicename"]=> string(7) "aner" ["user_email"]=> string(18)
    "infe" ["user_url"]=> string(0) "" ["user_registered"]=>
    string(19) "2013-0 1:02" ["user_activation_key"]=> string(0)
    "" ["user_status"]=> string(1) "0" ["display_name"]=> string(7)
    "Aner" } ["ID"]=> int(24) ["caps"]=> array(1) { ["subscriber"]=>
    bool(true) } ["cap_key"]=> string(22) "localhero_capabilities"
    ["roles"]=> array(1) { [0]=> string(10) "subscriber" } ["allcaps"]=>
    array(3) { ["read"]=> bool(true) ["level_0"]=> bool(true)
    ["subscriber"]=> bool(true) } ["filter"]=> NULL } }</p>
  </blockquote>
  
  <p>And How do I echo this ARRAY1[id]?</p>
  
  <p>Thanks to GWC</p>
  
  <p>I do it this way:</p>
  
  <pre><code>if ((ctype_alnum($_GET["key"])) &amp;&amp; (strlen($_GET["key"]) == 32)) {
  
  $lh_users = get_users( array(
  "meta_key" =&gt; "lh_scuritycode",
  "meta_value" =&gt; $_GET["key"],
  "number" =&gt; 1, "fields" =&gt; "ID"
  ) );
  
  $this_user = $lh_users[0];
  
  echo $this_user;
  </code></pre>