• I met some trouble. I tried to query user display_name in a custom mysql query foreach, but it failed. I have tried three method. new WP_User, get_user_by and get_userdata. but they only get back the result $user->display_name which is admin (ID=1 in table wp_users). failed get another $user->display_name which ID=2(3,4…) in table wp_users. What should I do to solve this question? many thanks.

    $results = mysql_query("SELECT * FROM custom_table");// In a custom database, not in database wp.
    while($row = mysql_fetch_array($results)) {
    global $wpdb;
    $user = new WP_User($row['user_id']);
    //$user = get_user_by('id',$row['user_id']);							//$user = get_userdata($row['user_id']);
    echo $user->display_name;
    }
Viewing 3 replies - 1 through 3 (of 3 total)
Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘query user display_name failed in a custom mysql query foreach’ is closed to new replies.