我在使用全局变量将值插入自定义数据库表时遇到问题:
// example that does not work
$user = wp_get_current_user();
$mega = $user->user_login; // this values will return blank when
// inserted into database especially
// when used with an if statement.
在进行数据库查询时,这些值在代码中工作正常,但一旦插入数据库,它将返回一个空值。
// here is my full code
global $wp;
$user = wp_get_current_user();
$mega = $user->user_login;
$age = 19;
// if records were not found in the database
// then insert new row with the details
if ( $age == 19) {
$fillup = $wpdb->insert("markrecord_table", array(
"username" => $mega,
"post_id" => 340,
"counted" => 1,
));
}