wordpressのSQL文 忘備録

<1列のみ取得する場合>

global $wpdb;

$query = "SELECT user_login, display_name FROM $wpdb->users WHERE ID = '".$value."' AND user_status=0";


$user_info = $wpdb->get_row($query);

 

(値を取り出す時)

$user_login = $user_info->user_login

$display_name $user_info->display_name

 

 

<値を1つのみ取得する場合>

global $wpdb;

$query = "SELECT user_email FROM $wpdb->users WHERE ID = '".$userid."' AND user_status=0";
$user_email = $wpdb->get_var($query);

 

<複数行を取得する場合>

global $wpdb;

$query = SELECT user_id FROM wp1_bp_xprofile_data WHERE field_id = '89' AND value LIKE '%".$val."%' AND user_id != '".$userid."'";

$results = $wpdb->get_results($query);

foreach ($results as $value) {

    $user_id = $value->user_id

}