在wp_get_Current_User数组函数中传递自定义字段值

时间:2015-12-15 作者:1991wp

How to pass the custom field values which were stored while creating a new user into the wp_get_current_user array function

当我打电话给wp_get_current_user() 函数我发现的结果如下:

WP_User Object
(
    [data] => stdClass Object
        (
            [ID] => 20
            [user_login] => testing
            [user_pass] => $P$BAfSwYFZEUKIkQyF30Eq7GN3HOUXFW/
            [user_nicename] => testing
            [user_email] => [email protected]
            [user_url] => 
            [user_registered] => 2015-12-15 07:11:35
            [user_activation_key] => 1450163495:$P$Br7QHNREuY.esEZdB3c92fK2CrW9QH.
            [user_status] => 0
            [display_name] => testing testing
            [token_key] => 
        )

    [ID] => 20
    [caps] => Array
        (
            [subscriber] => 1
        )

    [cap_key] => wp_capabilities
    [roles] => Array
        (
            [0] => subscriber
        )

    [allcaps] => Array
        (
            [read] => 1
            [level_0] => 1
            [subscriber] => 1
        )

    [filter] => 
)
但我希望答案是

WP_User Object
    (
        [data] => stdClass Object
            (
                [ID] => 20
                [user_login] => testing
                [user_pass] => $P$BAfSwYFZEUKIkQyF30Eq7GN3HOUXFW/
                [user_nicename] => testing
                [user_email] => [email protected]
                [user_url] => 
                [user_registered] => 2015-12-15 07:11:35
                [user_activation_key] => 1450163495:$P$Br7QHNREuY.esEZdB3c92fK2CrW9QH.
                [user_status] => 0
                [display_name] => testing testing
                [token_key] => 
                [client] => abc
                [user_groups] => test
            )

        [ID] => 20
        [caps] => Array
            (
                [subscriber] => 1
            )

        [cap_key] => wp_capabilities
        [roles] => Array
            (
                [0] => subscriber
            )

        [allcaps] => Array
            (
                [read] => 1
                [level_0] => 1
                [subscriber] => 1
            )

        [filter] => 
    )
比较[data] 两个阵列的一部分

我如何做到这一点?

提前谢谢你的帮助

2 个回复
SO网友:Hasan Uj Jaman

你可以简单地这样做。

$user = wp_get_current_user();
$user->data->client = $user->client; // $user->meta_key
$user->data->user_groups = $user->user_groups; // $user->meta_key

SO网友:1991wp

我找到了我问题的答案。无需在数组中传递值,我们可以调用单独的函数来获取基于当前用户的自定义字段的值,例如。get_user_meta($current->ID);

相关推荐

无法在模板函数.php中使用IS_HOME

我试图在标题中加载一个滑块,但只在主页上加载。如果有帮助的话,我正在使用Ultralight模板。我正在尝试(在template functions.php中)执行以下操作:<?php if ( is_page( \'home\' ) ) : ?> dynamic_sidebar( \'Homepage Widget\' ); <?php endif; ?> 但这行不通。现在,通过快速的google,我似乎需要将请