我正在尝试利用这个功能。我不明白为什么我仍然会遇到PHP错误。我所能理解的是,由于某种原因,模板无法访问$wpdb。我不知道函数中需要放置哪一行。包含此函数的php(在主题文件夹中)文件。请帮帮我!!
function submitWeightUpdate( $userid, $weight ) {
global $wpdb;
$result = $wpdb->insert( \'wp_weights\', array( \'user_id\' => $userid, \'current_weight\' => $weight ), array( \'%d\', \'%d\' ) );
if (empty($_POST[\'weight\'])) {
$return[\'error\'] = true;
$return[\'msg\'] = \'You did not enter a weight.\';
}
else {
$return[\'error\'] = false;
$return[\'msg\'] = \'You\\\'ve entered: \' . $weight . \' as your new weight.\';
}
echo json_encode($return);
}
我还尝试将主题设置为默认主题,但仍然无法正常工作,所以我不知道它会出什么问题!