2014-09-05 52 views
0

我想要一个关联数组的用户元数据字段。具体而言,我想存储用户投票投票的任何帖子。换句话说,我想有:wordpress元数据中的关联数组

for get_user_meta($ id,'vote_arr',true)提供:Array(post_id => 1,0,-1)其中1 0或-1告诉我是否用户投票了或者没有特定的帖子。

但是我有问题检索只是用get_user_meta的键值对的$值:

我已经尝试了各种组合:

$vote=get_user_meta(get_current_user_id(),'vote_arr['.$_POST[postId].']',true); 
$vote=get_user_meta(get_current_user_id(),'vote_arr['$_POST[postId]']',true); 
$vote=get_user_meta(get_current_user_id(),'vote_arr[$_POST[postId]]',true); 

没有人只提供了1, 0,-1值。

在此先感谢。

+0

它返回什么?它也应该是''vote_arr ['。$ _ POST ['postId']。']'' – Rob 2014-09-05 00:31:15

+0

您可以分享您尝试过的每个选项的输出,并且可以给我们一个数据库键和值的示例这是为用户存储的?这样我们可以帮助您缩小发生了什么问题。在get_user_meta末尾传递true应该使其不返回数组,而是返回该用户的该键的值。 – rmmoul 2014-09-05 00:31:33

+0

nvm,我只是分两步来做:$ old_vote_arr = get_user_meta(get_current_user_id(),'vote_arr',true); \t \t \t $ old_vote = $ old_vote_arr [$ _ POST ['postId']]; – bob 2014-09-05 00:40:45

回答

0

将这些保存在wp_option中,这将有助于存储asso数组。使用键作为“identifier_(userID)”。用户meta和post meta不能存储数组,但wp_options可以。使用get_option和update_option函数来检索数据。