0

I have a user registration form in the front end (in the Users admin section as well) with three extra fields (apart from default ones): birthday, country, language. their values are stored in usermeta table.

I have this action hook to retireve all meta data for the registered user:

add_action('user_register', 'new_user_func');

// user registration callback function
function new_user_func($userID) {
    $newUser = get_user_meta( $userID );
    $userMeta = array();
    foreach ($newUser as $key => $value) {
        $userMeta[$key] = $value[0];
    }
    //do something with $userMeta...
}

var_dump($userMeta) after submit doesn't give me the extra fields value though.. only defaults (first name, last name etc)

Anyone know what might be the case?

4

2 回答 2

0

您是否尝试通过以下方式获取值:

$meta = get_the_author_meta($meta_key, $user_id);

get_user_meta() 可能不支持您自己添加的元值。

如果这也不起作用,也许您需要查看如何创建新的元字段。这里有一个相当不错的教程:http: //justintadlock.com/archives/2009/09/10/adding-and-using-custom-user-profile-fields

于 2012-08-03T10:19:15.253 回答
0

阅读 user_register action的 de Codex 条目,它说:触发此操作时,并非所有用户元数据都已存储在数据库中。

于 2020-10-13T11:50:08.487 回答