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 请问下这个红框里面是什么文档或者记事本编辑器
  • ¥15 机器学习教材中的例题询问
  • ¥15 求.net core 几款免费的pdf编辑器
  • ¥15 为什么安装HCL 和virtualbox之后没有找到VirtualBoxHost-OnlyNetWork?
  • ¥15 C# P/Invoke的效率问题
  • ¥20 thinkphp适配人大金仓问题
  • ¥20 Oracle替换.dbf文件后无法连接,如何解决?(相关搜索:数据库|死循环)
  • ¥15 数据库数据成问号了,前台查询正常,数据库查询是?号
  • ¥15 算法使用了tf-idf,用手肘图确定k值确定不了,第四轮廓系数又太小才有0.006088746097507285,如何解决?(相关搜索:数据处理)
  • ¥15 彩灯控制电路,会的加我QQ1482956179