I'm trying to update post meta for a meta edd_download_files the meta is in the form of an array. It is from a plugin so i can do it via admin, but still there is need to do it programmatically.

$simple_txt_fld = get_post_meta( $thispost->ID, 'edd_price', true );

echo print_r($simple_txt_fld);

I recieve the output like this

Array ( [index] => 0 [attachment_id] => 0 [thumbnail_size] => [name] => [file] => https://milyin.com/ [condition] => all ) 1

As I see it is an array, now i want to update the file name in the array. I created the form, and tried to update meta valued for other things, there it worked.

The code that i tried was this:

                    if ( array_key_exists('Download_File_Link', $input_values) )        {   
                                $array= Array(
                                 "index" => "0",
                                 "attachment_id"=> "0",
                                 "thumbnail_size" => "",
                                "name" => "",
                                 "file" => $a,
                                 "condition" => "all" );

                update_post_meta($postid, 'edd_download_files', $array  ); 

Here I am trying to put it in array and doesnt seem to work

It doesn't update file at all. Please help me out with a solution to update post meta in an array form

  • Have you checked the value of $input_values['Download_File_Link']; what it will be returning..? – Gopala krishnan Sep 30 '19 at 13:03
  • It will be returning a url, like milyin.com user can fill the form with url and it would be returned in the file's $a i tried it to save it in another postmeta (not an array) and it worked as expected.... – Aditya Agarwal Sep 30 '19 at 13:55
  • Have you looked in the database itself to see whether perhaps the array is being serialized? If it is serialized, you'll have to unserialize it, update the link value, and then re-serialize it - otherwise if your new link URL has a different number of characters than the original, it corrupts the array. – WebElaine Sep 30 '19 at 15:36
  • Yes the value is serialised, i dont have knowledge about it, but i suppose showing the value as a:0 means it's serialised, so how can i unserialize and reserialize it – Aditya Agarwal Sep 30 '19 at 15:51
  • @webElaine I think we just need to reserialize it, because we are never using the actual values if the meta, we just create an array, take value from form and then update the Meta. So i think we just need to serialise it, how can we do it? – Aditya Agarwal Sep 30 '19 at 15:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.