【问题标题】:get options value from wp_options table从 wp_options 表中获取选项值
【发布时间】:2014-08-14 06:07:46
【问题描述】:

在我的 wp_options 表中,有一个名为 profile_fields 的字段,该字段的值如下所示

a:18:{
i:1;a:8:{
s:4:"type";s:8:"usermeta";s:4:"icon";s:8:"calendar";s:8:"position";s:1:"9";s:5:"field";s:6:"select";s:4:"name";s:15:"Graduation Year";s:4:"meta";s:15:"graduation_year";s:11:"meta_custom";s:0:"";s:6:"social";s:1:"0";s:8:"can_edit";s:1:"1";s:10:"allow_html";s:1:"0";s:8:"can_hide";s:1:"0";s:7:"private";s:1:"0";s:8:"required";s:1:"1";s:17:"show_to_user_role";s:1:"0";s:17:"edit_by_user_role";s:1:"0";
    s:16:"show_in_register";
    s:1:"1";
    s:9:"help_text";
    s:0:"";
    s:7:"choices";
    s:22:"1991
        1992
        1993
        1994";

 }
}

我必须做些什么才能让 s22 进入现场。(1991,1992,1993,1994)。 我尝试使用 var_dump() 转储值,但它只显示其他一些字段。

请大家帮帮我。

更新

我已经像这样从数据库中获取选项值

$a = get_option( 'upme_profile_fields' );
        print_r($a);

现在打印出来像

那里没有显示上面给定的内容(

a:18:{
    i:1;a:8:{
    s:4:"type";s:8:"......

)

【问题讨论】:

  • 这是一个序列化字符串,使用unserialize函数将其转换为数组。
  • @Rikesh 我会试试的
  • 你试过 ?
  • @Rikesh unserialize 需要字符串参数。但是这里我们有 objecj
  • @Sumurai8 我已删除重复的问题,请立即删除重复

标签: php database wordpress


【解决方案1】:

试试这个:-

$a = get_option( 'profile_fields' );
print_r($a);
// find the value you want to un-serialize, then, put as below

$arr = $a["YOUR VALUE KEY"];

$profile_arr = unserialize($arr);

print_r($profile_arr);

【讨论】:

  • 它显示:警告:unserialize() 期望参数 1 是字符串,给定数组
  • 上例中的 value 键是什么
  • 请粘贴 print_r($a) 的结果;这里
  • Array ( [50] => Array ( [position] => 50 [type] => separator [ meta ] => profile_info_separator [name] => Profile Info [private] => 0 [deleted ] => 0 [show_to_user_role] => 0 ) [60] => Array ( [position] => 60 [icon] => camera [field] => fileupload [type] => usermeta [ meta ] => user_pic [name ] => 个人资料图片 [can_hide] => 0 [can_edit] => 1 [私人] => 0 [社交] => 0 [已删除] => 0 [show_to_user_role] => 0 [edit_by_user_role] => 0 [help_text] => )
  • 在此我没有得到我提到的值
猜你喜欢
  • 2013-04-08
  • 2011-08-23
  • 2014-01-31
  • 2017-10-21
  • 1970-01-01
  • 2022-07-16
  • 2017-09-02
  • 2016-08-12
  • 2023-04-04
相关资源
最近更新 更多