How do I create a new usermeta field with a drop down selection values?
Im want to create a conditional statement for all users with a certain value of the new custom field I want.
For example,
The new field would be: Approved
The drop down values are: Yes and No
The conditional statement will recognize all users with the Approved field value of Yes. Then it will post a code.
Im working with the wp_get_current_user function(), which does exactly what I need, but I just need a new custom usermeta field. In the example the new usermeta field would be “artwork_approved.”
Example:
wp_get_current_user();
if ($current_user->artwork_approved == 'Yes'){
echo 'Thank you for approving your artwork!';
}
There seems to be no plugin for this and I really need this feature. I would really appreciate some advice on creating a new usermeta with drop down options.
*UPDATE:
I used the Register Plus Redux to create a new usermeta field, called “Artwork Approved.” I made it a drop down option, with options “No” and “Yes.” The No option is set as default.
This created the “Artwork Approved” usermeta field. I manage user accounts and choose either Yes or No. Now with this new usermeta field, Im using a function that should check if the current user has the Artwork Approved with value of Yes. Then it is supposed show a certain code.
Here is the if statement Im using with the new usermeta field:
<?php global $current_user; get_currentuserinfo(); if ($current_user->artwork_approved == 'Yes') { ?>
echo 'Your artwork is approved';
<?php } else { ?>
echo 'Your artwork is not approved';
<?php } ?>
But what’s happening is it’s not recognizing the first part of the if statement. If I log into any account with the artwork approved, the if statement only shows the “else” part even if I have the option “Yes” for Artwork Approved.
I don’t know why it isn’t recognizing the Yes Option as I have it in the statement.
Thanks
You can create a simple plugin to hook into the user profile actions and add a new field.
To add the field to the form you can hook into the
show_user_profile
andedit_user_profile
actions and output the form field HTML. The below uses a checkbox rather than a drop-down.Then you need to hook into the
personal_options_update
andedit_user_profile_update
actions, get the value of your field and save this as user meta.Your condition would then be as below.
Shouldn’t the second block of code read:
The value saved by
update_user_meta
is$_POST['artwork_approved']
notisset($_POST['artwork_approved'])
.