too long

im trying to add this to the wordpress database:

add_post_meta($attach_id_song, "playlist",'a:1:{i:0;a:19:{s:5:"title";s:26:'. $song_title .';s:3:"mp3";s:89:'. $wp_upload_dir['url'] .';s:7:"radioip";s:0:"";s:9:"radioport";s:0:"";s:11:"buy_title_a";s:0:"";s:10:"buy_icon_a";s:14:"cloud-download";s:10:"buy_link_a";s:0:"";s:11:"buy_title_b";s:0:"";s:10:"buy_icon_b";s:14:"cloud-download";s:10:"buy_link_b";s:0:"";s:11:"buy_title_c";s:0:"";s:10:"buy_icon_c";s:14:"cloud-download";s:10:"buy_link_c";s:0:"";s:11:"buy_title_d";s:0:"";s:10:"buy_icon_d";s:14:"cloud-download";s:10:"buy_link_d";s:0:"";s:10:"buy_custom";s:0:"";s:11:"lyric_title";s:0:"";s:5:"lyric";s:0:"";}}}');

but when added i get these errors:

Warning: Invalid argument supplied for foreach() in /home/sales/domains/lilopel.com/public_html/wouter/wordpress/wp-content/themes/remix/single-songs.php on line 48

and

Warning: Invalid argument supplied for foreach() in /home/sales/domains/lilopel.com/public_html/wouter/wordpress/wp-content/themes/remix/single-songs.php on line 418

and when i look in the database i see the metadata has changed into:

s:618:"a:1:{i:0;a:19:{s:5:"title";s:26:Javad Bayat  - Gharibaneh ;s:3:"mp3";s:89:http://wouter.lilopel.com/wordpress/wp-content/uploads/2016/02;s:7:"radioip";s:0:"";s:9:"radioport";s:0:"";s:11:"buy_title_a";s:0:"";s:10:"buy_icon_a";s:14:"cloud-download";s:10:"buy_link_a";s:0:"";s:11:"buy_title_b";s:0:"";s:10:"buy_icon_b";s:14:"cloud-download";s:10:"buy_link_b";s:0:"";s:11:"buy_title_c";s:0:"";s:10:"buy_icon_c";s:14:"cloud-download";s:10:"buy_link_c";s:0:"";s:11:"buy_title_d";s:0:"";s:10:"buy_icon_d";s:14:"cloud-download";s:10:"buy_link_d";s:0:"";s:10:"buy_custom";s:0:"";s:11:"lyric_title";s:0:"";s:5:"lyric";s:0:"";}}}";

any idea how to fix this

Strings saved in Wpdb with {} seem to be handled by wordpress automatically, you should never insert there any harcoded string manually. Had the same problem when trying to insert a string with arguments in similar format in the user meta table.

I ended up updating the data with specific functions for each attribute (e.g. $user->set_role()) instead of adding the string in the table. So, for you:

  1. try to find if there is a way of adding this metadata through other means. What kind of object are you updating? A song? try getting the object by its id and look in documentation (Wordpress API for your plugin?) if there are any functions for updating the objects title, link, etc. separately, without having to give the hardcoded string as it is in the database

  2. if this doesn't work, and if you are not using a plugin that stores the songs exactly in this format, and you can freely decide the structure of stored song data: split the metadata and add each attribute separately to the postmeta table. then, add/update each attribute separately with update_post_meta().

hope i could help

Should use an array instead of the string:

https://codex.wordpress.org/Function_Reference/add_post_meta

WP will convert the array to the correctly formatted string.