dsh77114 2014-09-05 00:25
浏览 27

wordpress元数据中的关联数组

I would like to have a user meta-data field that is an associative array. Specifically, I would like to store what the user voted for any posts voted for. In other words I would like to have:

for get_user_meta($id,'vote_arr',true) to provide: Array( post_id => 1, 0, -1) where 1 0 or -1 tells me if the user voted up down or neither for that specific post.

However I am having problems retrieving just the $value of the key-value pair using get_user_meta:

I have tried all kinds of combinations:

$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);

none of them provide just the 1,0,-1 value.

Thanks in advance.

  • 写回答

1条回答 默认 最新

  • dpbv85276 2014-09-05 00:59
    关注

    save these in wp_option that will help in storing asso array. use key as "identifier_(userID)". user meta and post meta cannot store array, but wp_options can. use get_option and update_option functions to retrieve data.

    评论

报告相同问题?

悬赏问题

  • ¥15 电力市场出清matlab yalmip kkt 双层优化问题
  • ¥30 ros小车路径规划实现不了,如何解决?(操作系统-ubuntu)
  • ¥20 matlab yalmip kkt 双层优化问题
  • ¥15 如何在3D高斯飞溅的渲染的场景中获得一个可控的旋转物体
  • ¥88 实在没有想法,需要个思路
  • ¥15 MATLAB报错输入参数太多
  • ¥15 python中合并修改日期相同的CSV文件并按照修改日期的名字命名文件
  • ¥15 有赏,i卡绘世画不出
  • ¥15 如何用stata画出文献中常见的安慰剂检验图
  • ¥15 c语言链表结构体数据插入