php - Add multiple values to a meta field -


i developing script in php, through can add values of post id in database (using wordpress cms).

this code:

$postid = $_post['post_id']; $users_ids = $_post['user_id']; $metavalueuser = $postid; $single = true;   $newvalue = $postid; $oldvalue = get_user_meta( $users_ids, 'post_likes', true ); $arrvalue = array($oldvalue,$newvalue); update_user_meta($users_ids, 'post_likes', $arrvalue); 

the problem code doesn't add multiple values.

whenever new value added, older value erased.

i need add value comma.

so can call them using foreach function.

$postid = $_post['post_id'];     $users_ids = $_post['user_id'];     $metavalueuser = $postid;     $single = true;       $newvalue = $postid;     $oldvalue = get_user_meta( $users_ids, 'post_likes', true );     $arrvalue =  $oldvalue.', '.$newvalue; // store comma seperated string     update_user_meta($users_ids, 'post_likes', $arrvalue);`enter code here` 

now after retriving value post meta can convert array using explode


Comments

Popular posts from this blog

c++ - CryptStringToBinary API behavior -

java.util.scanner - How to read and add only numbers to array from a text file -

iphone - Three second countdown in cocos2d -