Add Values to Existing WordPress User Meta Data

I am using SimpleXML_load_file to bring data into wordpress and then add data to user_meta_data.

I understand that you can pass an array of meta key values AT THE TIME that you are creating or updating the meta data but when I run the page again, with new XML data, it just overwrites the existing data.

Read More

What I want to happen is simply add another value to the same meta key. In a different instance (when the script runs again). here is what I am doing.

The reason for the 2 update_user_meta is that I am creating one meta key called “inbox-items” that contains ALL the ID’s for ALL the incoming email messages. The second, creates a new meta key with the ID that contains all the details of the message (date, msg, from, etc…)

                  $msg_array = array (
                                'msg-date' => $msg_date,
                                'msg-details' => $msg_msg,
                                'msg-id' => $msg_msgID,
                                'msg-keyword' => $msg_keyword,
                                'msg-from' => $msg_from
                                );    

update_user_meta($keyword_wpID,'inbox-items',(string) $inbox->IncomingMessage->TransactionID);
update_user_meta($keyword_wpID,(string) $inbox->IncomingMessage->TransactionID, $msg_array);
$get_inboxID = get_user_meta($keyword_wpID,'inbox-items', false);

     foreach ($get_inboxID as $i) {
                $get_msgs = get_user_meta($keyword_wpID,$i, false); 
                echo '<br/><br/>';
                echo print_r($get_msgs);
                }

Related posts

Leave a Reply

1 comment