将元值另存为数组数组

时间:2018-02-08 作者:Raju

如何以以下格式保存元值:

array(
   array(
    \'title\' => \'something\',
    \'price\' => \'something\',
   ),
   array(
    \'title\' => \'something\',
    \'price\' => \'something\',
   ),
)

1 个回复
SO网友:Milo

如果不需要查询数据,可以直接将数组传递给post元函数,WordPress会自动为您序列化/取消序列化数据。

$your_array = array(
   array(
    \'title\' => \'something\',
    \'price\' => \'something\',
   ),
   array(
    \'title\' => \'something\',
    \'price\' => \'something\',
   ),
);

update_post_meta( $post_id, \'your_key\', $your_array );

结束