douzheng5717 2018-01-23 13:06
浏览 38

WordPress:用户meta不会抓取PHP

I am trying to get this meta data to display:

public static function user_register($user_id) {
    //The user_id is grabbed from wordpress and this is run after user 
    //registration, echo does display correctly the user_id as 806 (example)

    //$data = empty.. which makes no sense!!
    $data = get_user_meta ( $user_id , 'business', true );

    //Everything undernearth runs as it should..
    $grID = $wpdb->get_var("SELECT group_id FROM wp_groups_group WHERE name = '$data'");
    Groups_User_Group::create( array( 'user_id' => $user_id, 'group_id' => $grID ));
}

Some confirmations:
Yes! setting variable $data = "806"; does fix it!
However, this variable changes... I can't have a static string (806) for this. It has to be the current user.
The database is correct, there is a meta for business and the value is set (DB also seems to be fine)

user_id == 806 (confirmed with testing below)

public static function user_register( $user_id ) {
    if($user_id == 806){
        $data = "806";
    }
    $grID = $wpdb->get_var("SELECT group_id FROM wp_groups_group WHERE name = '$data'");
    Groups_User_Group::create( array( 'user_id' => $user_id, 'group_id' => $grID ));
}

Other scripts that I have tried replacing $data with:

$data = get_user_meta ( get_current_user_id() , 'business', true );

and

$usr = get_current_user_id();
$data = get_user_meta ( $usr , 'business', true );
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥170 如图所示配置eNSP
    • ¥20 docker里部署springboot项目,访问不到扬声器
    • ¥15 netty整合springboot之后自动重连失效
    • ¥15 悬赏!微信开发者工具报错,求帮改
    • ¥20 wireshark抓不到vlan
    • ¥20 关于#stm32#的问题:需要指导自动酸碱滴定仪的原理图程序代码及仿真
    • ¥20 设计一款异域新娘的视频相亲软件需要哪些技术支持
    • ¥15 stata安慰剂检验作图但是真实值不出现在图上
    • ¥15 c程序不知道为什么得不到结果
    • ¥15 键盘指令混乱情况下的启动盘系统重装