从wp_postmeta检索数据

我知道这可能是一个愚蠢的问题。 我正在尝试从wordpress表wp_postmeta中检索数据,特别是meta_value列。 在PHP中是否有一个函数可以从这种数据中获取每个字段?</ p>

例如,如何从此处获取“Gabriela Castro en Costa Rica”值</ p>

 <代码>一个:1:{S:14: “计费卖方”;一个:3:{S:4: “姓名”; S:14: “计费卖方”; S:5:  “价值”; s:29:“Gabriela Castro en Costa Rica”; s:5:“label”; s:26:“请选择一个选项。”;}} 
</ code> </ pre> \ n

谢谢。</ p>
</ div>

展开原文

原文

I know this is maybe a dumb question. I am trying to retrieve data from the wordpress table wp_postmeta, specifically the meta_value column. Is there a function in php to get every field from that kind of data?

For example how can I get the "Gabriela Castro en Costa Rica" value from this

a:1:{s:14:"billing-seller";a:3:{s:4:"name";s:14:"billing-seller";s:5:"value";s:29:"Gabriela Castro en Costa Rica";s:5:"label";s:26:"Select one option, please.";}}

Thanks.

dt3999
dt3999 你在哪里查询数据?插件/主题的模板functions.php文件,还是“外部”脚本?
6 年多之前 回复

3个回答



这看起来像一个序列化数组,我不熟悉Wordpress但可能会尝试这样的事情:</ p>

< pre> get_user_meta('99999','your-key',true);
</ code> </ pre>

您可以在此处找到更多关于get_user_meta的信息:</ p>

https://wordpress.stackexchange.com/questions/9716/how-to-retrieve-the-value-stored-in-a-multi-dimensional-array-and-sum-the-entrie </ p>
</ div>

展开原文

原文

This seems like a serialized array, im not familiar with Wordpress but maybe try something like this:

get_user_meta( '99999', 'your-key', true );

You can find more information to get_user_meta here:

https://wordpress.stackexchange.com/questions/9716/how-to-retrieve-the-value-stored-in-a-multi-dimensional-array-and-sum-the-entrie

doudu8291
doudu8291 我想你可能是指get_post_meta?
6 年多之前 回复
doushi2902
doushi2902 谢谢,我尝试但阅读文档,我看到我需要一个用户ID,我的代码没有
6 年多之前 回复



get_post_meta()</ code>是您需要使用的功能。 </ p>

  $ value = get_post_meta($ post_id,'key',true); 
</ code> </ pre>

$ value </ code>将是您的字符串。</ p>

https:/ /codex.wordpress.org/Function_Reference/get_post_meta </ p>
</ div>

展开原文

原文

get_post_meta() is the function you need to use.

$value = get_post_meta( $post_id, 'key', true );

Where $value will be your string.

https://codex.wordpress.org/Function_Reference/get_post_meta

First of all, the serialized string I posted came from doing this:

get_post_meta($order->orders, '_custom_billing_fields', true);

That was giving me this(the original question):

a:1:{s:14:"billing-seller";a:3:{s:4:"name";s:14:"billing-seller";s:5:"value";s:29:"Gabriela Castro en Costa Rica";s:5:"label";s:26:"Select one option, please.";}} 

Now this is what I did to get the value I was trying to substract:

$sellerBigArray = (array)maybe_unserialize(get_post_meta($order->orders, '_custom_billing_fields', true));

$sellerArray=$sellerBigArray['billing-seller'];

$seller=$sellerArray['value'];

I hope it helps.

Bye

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐