0

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?

4
  • How this data being saved? Do you already have a metabox for that?
    – Abhik
    May 21, 2022 at 7:06
  • I need to create the metabox but I don't know how to adapt it to my needs
    – Peanuts
    May 21, 2022 at 15:09
  • This will help you to get started.
    – Abhik
    May 21, 2022 at 16:11
  • Ok thanks, my problem is I can create an "average" metabox to updat a "classic" plain custom field, but I don't know how to create a metabox that can update KEY/VALUE and append new information to the table...
    – Peanuts
    May 23, 2022 at 2:46

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Browse other questions tagged or ask your own question.