Community Support Forums — WordPress® ( Users Helping Users ) — 2011-06-02T19:45:01-05:00 http://www.primothemes.com/forums/feed.php?f=4&t=6649 2011-06-02T19:45:01-05:00 http://www.primothemes.com/forums/viewtopic.php?t=6649&p=16584#p16584 <![CDATA[Re: How to update a custom field?]]>

Statistics: Posted by Cristián Lávaque — June 2nd, 2011, 7:45 pm


]]>
2011-06-02T19:05:02-05:00 http://www.primothemes.com/forums/viewtopic.php?t=6649&p=16580#p16580 <![CDATA[Re: How to update a custom field?]]> Well... thanks soo much for helping me out mate.

Cheers
Nad

Statistics: Posted by talkdownunder — June 2nd, 2011, 7:05 pm


]]>
2011-06-02T13:45:00-05:00 http://www.primothemes.com/forums/viewtopic.php?t=6649&p=16563#p16563 <![CDATA[Re: How to update a custom field?]]>

Statistics: Posted by Cristián Lávaque — June 2nd, 2011, 1:45 pm


]]>
2011-06-02T10:15:46-05:00 http://www.primothemes.com/forums/viewtopic.php?t=6649&p=16552#p16552 <![CDATA[Re: How to update a custom field?]]>
Ahhhh, now I see how to update a Custom Field via the proper syntax of 'update_user_option'. Thank you so much. Works perfectly. I have a lot of Custom Fields in my site, and an entire separate Admin area (outside of WordPress), so it's great to see how the two tie together. You the man.

- Adam

Statistics: Posted by adamarling — June 2nd, 2011, 10:15 am


]]>
2011-06-01T21:15:28-05:00 http://www.primothemes.com/forums/viewtopic.php?t=6649&p=16530#p16530 <![CDATA[Re: How to update a custom field?]]> print_r($s2_custom_fields) to see what it's like, and make sure you edit it properly before updating it, and read the update function documentation. ;)

Here's your example a bit edited:

Code:
$s2_custom_fields = get_user_option('s2member_custom_fields', $user_id);
echo 'First time value is: ' . ($s2_custom_fields['first_time'] ? 'true' : 'false') . '<br/>';

$s2_custom_fields['first_time'] = false;
update_user_option($user_id, 's2member_custom_fields', $s2_custom_fields);

$s2_custom_fields = get_user_option('s2member_custom_fields', $user_id);
echo 'Now first time value is: ' . ($s2_custom_fields['first_time'] ? 'true' : 'false') . '<br/>';
 


I suggest using true or false for your field, instead of yes or no.

I hope it helps. :)

Statistics: Posted by Cristián Lávaque — June 1st, 2011, 9:15 pm


]]>
2011-06-01T18:24:37-05:00 http://www.primothemes.com/forums/viewtopic.php?t=6649&p=16524#p16524 <![CDATA[Re: How to update a custom field?]]>
This code returns the same value for "first_time" custom field, means "update_user_option" didn't work. Soo frustrated now. Much appreciated your help.

Code:
$s2_custom_fields = get_user_option('s2member_custom_fields', $user_id);
echo "first time value is:".$s2_custom_fields['first_time']."<br/>";

update_user_option($user_id, 'first_time', 'No');   

$s2_custom_fields = get_user_option('s2member_custom_fields', $user_id);
echo "Now first time value is:".$s2_custom_fields['first_time'];


-
For that age calculation, I need to display age in the user edit screen. If I do that manipulating user edit page, WP updates will replace that and I loose the changes I made right? So only option I could see having a cron to update custom field "age". Any other suggestions much appreciated.

Cheers
Nad

Statistics: Posted by talkdownunder — June 1st, 2011, 6:24 pm


]]>
2011-06-01T15:36:59-05:00 http://www.primothemes.com/forums/viewtopic.php?t=6649&p=16518#p16518 <![CDATA[Re: How to update a custom field?]]> get_user_option returns and follow that format when you update_user_option. Let me know if that helps.

Statistics: Posted by Cristián Lávaque — June 1st, 2011, 3:36 pm


]]>
2011-06-01T13:44:04-05:00 http://www.primothemes.com/forums/viewtopic.php?t=6649&p=16508#p16508 <![CDATA[Re: How to update a custom field?]]>
Through my own custom PHP script, I'd like to update the value of a Custom Field ('b_city'). Here's my code:

Code:
$user_id = 6;
update_user_meta($user_id, 'b_city', 'New City Name');


and I've also tried:

Code:
update_user_option($user_id, 'b_city', 'New City Name')


...however neither works. Is there another way I should refer to the Custom Field title, or am I using the wrong function? I can't find answers anywhere for the life of me.

thanks,
Adam

Statistics: Posted by adamarling — June 1st, 2011, 1:44 pm


]]>
2011-06-01T10:15:09-05:00 http://www.primothemes.com/forums/viewtopic.php?t=6649&p=16483#p16483 <![CDATA[Re: How to update a custom field?]]>
You could have the field be the birthdate instead of age, then you'd figure out the age any time you need it without having to edit the custom field's value.

About the first login, you can get the s2Member custom fields in an array with

Code:
$s2_custom_fields = get_user_option('s2member_custom_fields', $user_id); 
* If you don't give it the user ID, it'll default to the current user.

Check the $s2_custom_fields['firlst_login'] and if true update the value to false. Try the update_user_option WP function. https://codex.wordpress.org/Function_Re ... ser_option

Statistics: Posted by Cristián Lávaque — June 1st, 2011, 10:15 am


]]>
2011-06-01T02:08:49-05:00 http://www.primothemes.com/forums/viewtopic.php?t=6649&p=16473#p16473 <![CDATA[How to update a custom field?]]>
I want to update 2 custom fields.
One to check if user is login for the first time, then change the value to 0.
Second is the age, a cron job runs every midnight to update this field.

- I'm struggling to find a way to update a custom field. Can anyone shed a light please.
- And if I write a simple PHP script for the cron, will it work with this s2Member custom filed data structure? Should I use any special method for this.

Please help. Spent many hours on this already. Quick help much appreciated.

Cheers
Nad

Statistics: Posted by talkdownunder — June 1st, 2011, 2:08 am


]]>