I am hoping someone can help me out.
I have created a custom meta box and trying to store an array, but when using update_post_meta, it doesn't seem to be storing it as an array.
I am getting the info via an api and it seems to be breaking down when going from the textarea to the update_post_meta.
I have tried serialize, unserialize, maybe_serialize, maybe_unserialize etc. Anyway here is my code.
$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>";
I have tested that the textarea is an array using echo is_array($cast) ? 'Array' : 'not an Array'; and it's returning Array.
So I figure the problem is further down at save function
$actors_array = $_POST['actors_array'];
update_post_meta( $post_id, 'actors_array', $actors_array );
Once stored and I use $cast = get_post_meta it seems it has not been stored correctly.
When testing echo is_array($cast) ? 'Array' : 'not an Array'; it returns not an array.
echo"<pre>";print_r($cast);echo"</pre>";
returns
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',
),...
So I am really hoping someone can help me out please.
Thanks :)
$_POSTit's already a string value.