[wp-hackers] array_push on update_user_meta

J.D. Grimes jdg at codesymphony.co
Thu Oct 31 18:32:38 UTC 2013


I would do this:

$profileID = $_POST['profileID'];

$chkMetaValue = get_user_meta($userID,"friends");

if ( ! is_array($chkMetaValue) )
	$chkMetaValue = array();

$chkMetaValue[] = $profileID; // or use array_push()

update_user_meta( $userID, 'friends', $chkMetaValue );

-J.D.

On Oct 31, 2013, at 1:32 PM, BenderisGreat <greglancaster71 at gmail.com> wrote:

> I am not sure exactly how this would work because I start with an empty
> meta_value field.  I dont think I can use array_push if there is not at
> least one value in the field, correct?  
> 
> So maybe something like this:
> 
> $profileID = $_POST['profileID'];
> 
> $chkMetaValue = get_user_meta($userID,"friends");
> 	if (!empty($chkMetaValue))
> 		{
> 		array_push($profileID);
> 		} else {
> 		$profileID;
> 		}
> 
> update_user_meta( $userID, 'friends', $chkMetaValue );
> 
> Is that right?
> 
> 
> 
> 
> --
> View this message in context: http://wordpress-hackers.1065353.n5.nabble.com/array-push-on-update-user-meta-tp42688.html
> Sent from the Wordpress Hackers mailing list archive at Nabble.com.
> _______________________________________________
> wp-hackers mailing list
> wp-hackers at lists.automattic.com
> http://lists.automattic.com/mailman/listinfo/wp-hackers



More information about the wp-hackers mailing list