wp_postmeta表中的WooCommerce序列化元值数组 [英] WooCommerce serialized meta value array in wp_postmeta table
问题描述
我正在通过SQL插入项目和属性.一切正常,但我无法弄清楚wp_postmeta中的_product_attributes
I am inserting items and attributes via SQL. Everything works fine, but i cannot figure it out how the _product_attributes in wp_postmeta
我理解逻辑,但s:7:"pa_hrup"<-我在哪里获得7 和s:31:"pa_kapaciteta-rezervoarja-za-go"<-我在哪里获得31 ..
I understand the logic, except the s:7:"pa_hrup" <-- where do i get 7 and s:31:"pa_kapaciteta-rezervoarja-za-go" <-- where do i get 31..
a:2:{s:7:"pa_hrup";a:6:{s:4:"name";s:7:"pa_hrup";s:5:"value";s:0:"";s:8:"position";i:0;s:10:"is_visible";i:1;s:12:"is_variation";i:0;s:11:"is_taxonomy";i:1;}s:31:"pa_kapaciteta-rezervoarja-za-go";a:6:{s:4:"name";s:31:"pa_kapaciteta-rezervoarja-za-go";s:5:"value";s:0:"";s:8:"position";i:1;s:10:"is_visible";i:1;s:12:"is_variation";i:0;s:11:"is_taxonomy";i:1;}}
推荐答案
这是元数据字符串序列化的数组,在这种情况下,s:31
是pa_kapaciteta-rezervoarja-za-go
的长度. a:6
是每个数组(或子数组)的ok键/值对项的数量.
It is a meta data string serialized array and s:31
is the length of pa_kapaciteta-rezervoarja-za-go
in this case. a:6
is the number ok key/value pairs items for each array (or sub array).
因此是序列化的数组:
- 对于数组,总是以
a:
开头,加上数组中的键/值对的项数和:
. - 然后
{
项开始 - 然后
s:
表示字符串,加上字符串项(键或值)的长度,:
加上键或值字符串. - 然后
;
分隔每个键或值组件 - 然后
}
结束项目
- always start with
a:
for array, plus the number of items key/value pairs in it and:
. - then
{
for items start - then
s:
for string, plus the lenght of the string item (key or value) and:
, plus the key or value string. - then
;
to separate each key or value component - then
}
for items end
序列化的数组,可以使用WordPress 反序列化. > maybe_unserialize()
(或PHP中的unserialize()
).
可以使用WordPress 序列化进行序列化 c12> (或PHP中的serialize()
).
Serialized arrays, can be unserialized using WordPress maybe_unserialize()
(or unserialize()
in PHP).
A normal array can be serialized using using WordPress maybe_serialize()
(or serialize()
in PHP).
诸如add_post_meta()或update_post_meta()之类的Wordpress函数将始终对数组进行序列化,然后再将meta_value
保存在wp_postmeta
表中.
Wordpress functions like add_post_meta() or update_post_meta() will always serialize an arrays before saving a meta_value
in wp_postmeta
table.
WooCommerce与WC_Data
方法具有相同的作用"rel =" nofollow noreferrer> CRUD对象和所有相关的数据存储类.
Same thing for WooCommerce with some related WC_Data
method as save()
on CRUD Objects and all related data stores classes.
在序列化的字符串数组上使用 maybe_unserialize()
会给出:
using maybe_unserialize()
on your serialized string array will give:
$values = array(
'pa_hrup' => array(
'name' => 'pa_hrup',
'value' => '',
'position' => '0',
'is_visible' => '1',
'is_variation' => '0',
'is_taxonomy' => '1'
),
'pa_kapaciteta-rezervoarja-za-go' => array(
'name' => 'pa_kapaciteta-rezervoarja-za-go',
'value' => '',
'position' => '1',
'is_visible' => '1',
'is_variation' => '0',
'is_taxonomy' => '1'
)
);
这篇关于wp_postmeta表中的WooCommerce序列化元值数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!