我有$user = wp_get_current_user();
数组。当我打印它时会显示
WP_User Object
(
[data] => stdClass Object
(
[ID] => 169 // I wanted the Value of ID
[user_login] => madhuri@gmail.com
[user_pass] => $P$BN2ibVoWTXB1DIsdcTnpVV03DBz8od0
[user_nicename] => madhurigmail-com
[user_email] => madhuri@gmail.com
[user_url] =>
[user_registered] => 2015-11-17 09:54:57
[user_activation_key] =>
[user_status] => 0
[display_name] => Madhuri Kashid
[latitude] =>
[longitude] =>
[role] =>
)
我只想要ID的值。
我想将ID的商店值转换为$UserId
提前致谢
答案 0 :(得分:0)
你得对象不是数组
尝试
# -*- coding: utf-8 -*-
from django.conf.urls import url
from django.utils.translation import ugettext_lazy as _
from django.views.generic.base import TemplateView
urlpatterns = [
url(r'^$', TemplateView.as_view(template_name="index.html"), name='home'),
url(_(r'^privacy-policy/$'), TemplateView.as_view(template_name="privacy-policy.html"), name='privacy-policy'),
]
答案 1 :(得分:0)
根据我的评论,要访问对象内的属性,请使用' - >'操作
$UserId = $user->data->ID;
答案 2 :(得分:0)
这是一个对象。因此,$UserId = $user->data->ID;
如果要将其作为数组访问,请先将其类型转换为数组,
$array = (array) $user;$user_id = $array['data']['ID'];