First: when you store data it gets serialized, and this is where these extra s:301:
and stuff like that coming from.
If you are using ACF plugin, at least i see it with functions get_field()
update_field()
You need to pass in just a value you want to store in, and it will serialize and unserialize data for you behind the scenes.
What I also see is by field name player_0_embed_player
is – you have a repeater with name player
and there’s a sub field named embed_player
.
What you can do to get value from subfield is simply
$all_rows = get_field('player', $post_id); // you'll have array of rows
$your_value = isset( $all_rows[0]['embed_player'] ) ? $all_rows[0]['embed_player'] : ''; // get value of subfield from first row if it exists.
update_field('ab_embedgroup', $your_value, $post_id); // save this value to other field. i don't know why but your code does it.
//I also have no idea why you create some `$query` variable and assign it twice.
Value that is stored in database will be serialized by ACF when you save it.
UPD: after clarification
You have these data when you unserialize a metadata that were read somehow.
Array
(
[0] => Array
(
[ab_hostname] => #HLS
[ab_embed] => <iframe width="1263" height="480" src="https://www.youtube.com/embed/5Gsdtetr1zo" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
[_state] => expanded
)
)
It’s data structure is [ [ ab_hostname, ab_embed, _state ] ]
As I understand your target data structure in ab_embedgroup
field (which is of type Group
) is [ [ab_hostname, ab_embed ] ]
Why you can’t just do this ?
$unserialized_data = maybe_unserialize($some_data_in_serialized_form_gathered_somehow);
$data_to_save = [
'ab_hostname' => $unserialized_data['ab_hostname'],
'ab_embed' => $unserialized_data['ab_embed'],
];
$data_to_save_as_group_field = [ $data_to_save ]; // it expects array of arrays with single array inside as it's group.
update_field( 'ab_embedgroup', $data_to_save_as_group_field, $post_id );