Custom Field: how to save array of multiple key-values in WordPress

I have this kind of data on my database:

wp:postmeta

    wp:meta_key
        ![CDATA[property_icalendar_import_multi]]
    /wp:meta_key
    
    wp:meta_value ![CDATA[a:2:{i:0;a:2:{s:4:feed;s:86:https://www.example.com/ics-files/property.ics;s:4:name;s:20:IMPORT_1;}i:1;a:2:{s:4:feed;s:56:https://www.example.com/ical/property.ics;s:4:name;s:16:IMPORT_2;}}]]
    /wp:meta_value
    
/wp:postmeta

As you can see, on meta_value I have two pairs of serialized data name1/feed1 and name2/feed2.

I wish to add, via custom fields, more instances to that array name3/feed3). But I don't know how to do it.

I was able to retrive the data so far:

    ?php
    $property_icalendar_import_multi = get_post_meta($edit_id, 'property_icalendar_import_multi', true);

    if(is_array($property_icalendar_import_multi)){
            foreach($property_icalendar_import_multi as $key=$feed_data){
                print $feed_data['name'];
                print $feed_data['feed'];
            }

        }else{
            esc_html_e('nothing');
        }

    ?

My question is now, how can I update (edit or add) this data with a metabox?

I know I have to use update_post_meta but I'm not sure how.

Can someone point me on the right direction?

Topic array custom-field Wordpress

Category Web

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.