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
Post a Comment