title: Get wordpress user metadata with custom function in external script in same server
body: <p>I have wordpress and script "B" installed in the same server. In script "B", I am trying to pull a user metadata from wordpress database so it can be displayed. I have the script below, but for some reason the foreach is not outputing nothing. I tested the query in phpmyadmin and it returns the rows, but, again, the foreach is not outputing nothing when I do it in the script. $mydb was initialized a few rows above. Please help. Thank you!</p>
  
  <pre><code>$query = "
          SELECT wp_users.ID AS id_1, wp_users.user_login AS username, wp_usermeta.user_id AS id_2, wp_usermeta.meta_key AS metakey, wp_usermeta.meta_value AS metavalue
          FROM wp_users
          LEFT JOIN wp_usermeta 
          ON wp_users.ID = wp_usermeta.user_id
          WHERE wp_users.user_login = '" . $username. "'
      ";
  
      $results = $mydb-&gt;get_results( $query );
      foreach ( $results as $result ) 
      {
          echo $result-&gt;metavalue."&lt;br /&gt;";
      }
  </code></pre>