我希望有人能帮助我。
我创建了一个自定义元框并尝试存储一个数组,但在使用update_post_meta
, 它似乎没有将其存储为数组。
我通过api获取信息,从文本区域到update_post_meta
.
我试过了serialize
, unserialize
, maybe_serialize
, maybe_unserialize
等等,这是我的代码。
$movieCast(array)
array (
0 =>
array (
\'actor\' => \'Anthony Hopkins\',
\'actor_char\' => \'Alfred Hitchcock\',
\'actor_link\' => \'anthony-hopkins\',
\'img_path\' => \'/oDMLEhFmXLkTlUnErs0RxRua7kN.jpg\',
),
1 =>
array (
\'actor\' => \'Helen Mirren\',
\'actor_char\' => \'Alma Reville\',
\'actor_link\' => \'helen-mirren\',
\'img_path\' => \'/dRYchPNm8WCXxWHcGtUwq9VLra1.jpg\',
),
2 =>
array (
\'actor\' => \'Scarlett Johansson\',
\'actor_char\' => \'Janet Leigh\',
\'actor_link\' => \'scarlett-johansson\',
\'img_path\' => \'/dZ4uNJtLQkGlJ76eePrXYqUDWgn.jpg\',
),...
echo "<textarea id=\'actors_array\' name=\'actors_array\' rows=\'5\' cols=\'120\'>" ?><?php var_export($movieCast); echo "</textarea>";
我已经测试了textarea是一个数组,使用
echo is_array($cast) ? \'Array\' : \'not an Array\';
它又回来了
Array
.
因此,我认为问题在保存功能上更为严重
$actors_array = $_POST[\'actors_array\'];
update_post_meta( $post_id, \'actors_array\', $actors_array );
一旦存储并使用
$cast = get_post_meta
似乎没有正确存储。
测试时echo is_array($cast) ? \'Array\' : \'not an Array\';
它返回not an array
.
echo"<pre>";print_r($cast);echo"</pre>";
退货
array (
0 =>
array (
\'actor\' => \'Anthony Hopkins\',
\'actor_char\' => \'Alfred Hitchcock\',
\'actor_link\' => \'anthony-hopkins\',
\'img_path\' => \'/oDMLEhFmXLkTlUnErs0RxRua7kN.jpg\',
),
1 =>
array (
\'actor\' => \'Helen Mirren\',
\'actor_char\' => \'Alma Reville\',
\'actor_link\' => \'helen-mirren\',
\'img_path\' => \'/dRYchPNm8WCXxWHcGtUwq9VLra1.jpg\',
),
2 =>
array (
\'actor\' => \'Scarlett Johansson\',
\'actor_char\' => \'Janet Leigh\',
\'actor_link\' => \'scarlett-johansson\',
\'img_path\' => \'/dZ4uNJtLQkGlJ76eePrXYqUDWgn.jpg\',
),...
所以我真的希望有人能帮我。
谢谢:)