I have data stored in a custom field in array as such
a:5:{i:0;a:1:{s:12:"product_desc";s:44:"Value1";}i:1;a:1:{s:12:"product_desc";s:24:"Value2";}i:2;a:1:{s:12:"product_desc";s:31:"Value3";}i:3;a:1:{s:12:"product_desc";s:41:"Value4";}i:4;a:1:{s:12:"product_desc";s:39:"Value5";}}
I want to extract the values of the sub_array product_desc and update the custom field meta_value.
I know wordpress have maybe_unserialize to unserialize the data but what to do next to extract the sub_array values?
add_action( 'init', function() {
if ( 'migrate' !== filter_input( INPUT_GET, 'action' ) ) {
return;
}
$query = new WP_Query( [
'posts_per_page' => -1,
'post_type' => 'post',
'post_status' => 'any',
] );
if ( ! $query->have_posts() ) {
return;
}
while ( $query->have_posts() ) {
$query->the_post();
$field_id_1 = 'podu';
$field_value_1 = get_post_meta( get_the_ID(), $field_id_1, true );
$data = maybe_unserialize( $field_value_1 );
//How to extract sub_array values from $data?
}
} );