我使用WordPress網站中的以下代碼從wp_cp表中提取作者ID,點數,並且完美地工作。我現在正在嘗試的是在用戶ID旁邊獲取用戶頭像。我如何在代碼中獲得用戶頭像?在WordPress中的MySQL查詢中獲取作者的頭像
<?php
global $wpdb;
/* wpdb class should not be called directly.global $wpdb variable is an instantiation of the class already set up to talk to the WordPress database */
$result = $wpdb->get_results("SELECT uid,sum(points) as pt FROM wp_cp where timestamp between '2015-12-12' and '2015-12-31' group by uid "); /*mulitple row results can be pulled from the database with get_results function and outputs an object which is stored in $result */
//echo "<pre>"; print_r($result); echo "</pre>";
/* If you require you may print and view the contents of $result object */
echo "uid"." "."pt"."<br><br>";
foreach($result as $row)
{
echo $row->uid." ".$row->pt."<br>";
}
/* Print the contents of $result looping through each row returned in the result */
?>
什麼是wp_cp?那是一個插件數據庫表嗎?通常有辦法做這些類型的事情,而不用在WordPress中編寫原始數據庫查詢。 – MillerMedia
是的,它是一個插件數據庫table.I需要使用這張表來獲得我的自定義數據,但沒有辦法獲得avator – Mithu
是否將'uid'與wp_users表中的用戶ID保存爲相同的值? – MillerMedia