[wp-hackers] array_push on update_user_meta
Gregory Lancaster
greglancaster71 at gmail.com
Thu Oct 31 18:48:03 UTC 2013
That works easier :) Once someone is friended I have it set so an unfriend
button replaces the add friend button via ajax. Is it necessary to write
another function for deleting a person? Not sure exactly how to make the
new button function since the data being sent is not attached to the button
in any way. maybe I could add a value to the button that says remove or
add, which would be passed to the function and determine what action to
take?
On Thu, Oct 31, 2013 at 11:32 AM, J.D. Grimes <jdg at codesymphony.co> wrote:
> 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
>
> _______________________________________________
> 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