How can i update/remove/empty a sub-array on user post submission in admin area?
here ist the reference on how to update nested array i am using but it is not working
if ( $post->post_type == 'ds_product' ) {
if ( isset( $_POST['meta'] ) ) {
if ( !empty($_POST['meta']['ds_product_gallery']) ){
$gallery_data = [];
for ($i = 0; $i < count( $_POST['meta']['ds_product_gallery']['picture'] ); $i++ )
{
if ( !empty($_POST['meta']['ds_product_gallery']['picture'][ $i ]))
{
$gallery_data['picture'][ ] = $_POST['meta']['ds_product_gallery']['picture'][ $i ];
$gallery_data['figcaption'][ ] = $_POST['meta']['ds_product_gallery']['figcaption'][ $i ];
}
}
if ( !empty($gallery_data) ) {
$_POST['meta']['ds_product_gallery'] = $gallery_data;
}
}else{
// this section doesn't clear the array
$data = get_post_meta( $post->ID, 'meta', true );
$data['ds_product_gallery'][0][0] = [];
update_post_meta( $post_ID, 'meta', $data[0] );
}
foreach( $_POST['meta'] as $key => $value ){
update_post_meta( $post_id, $key, $value );
}
}
}