Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I am trying to create a ranking based on user donation, my problem is I am not sure if wordpress user meta support append For each Project a user can donate money via paypal

In WordPress User Meta I am not sure how if is possible to append and integrate 2 column field for each donation amount and project made

1st field is a dropdown field(containing the projects) = second field(amount)

The project list will be handled by a custom post type with a custom field of amount and if the user donated to that page it will be credited to the current user and update the project and amount field.

in other words, i would like to append a user meta in the admin via the front end, i know its possible appending via backend but how about if the data is coming from the front end any security or limitation?

$user_id = get_current_user($id);
$project = $product_name;
$amount = $project_amount
If ($project != $product_name) { 
**add_user_meta( $user_id, '$project', ??);**
**add_user_meta( $user_id, '$amount', ??);**
}
else
{
 **add_user_meta( $user_id, '$project', ??);**
 **add_user_meta( $user_id, '$amount', ??);**
}

the problem now is the how would I add the project and amount data at the same column or append another row if the project is not identical

share|improve this question
1  
Sure, it's possible. As is, I suspect this question will be closed because you didn't try to solve it yourself and provide the code you had. If you do, I bet people will be happy to help. –  Andrew Bartel Jun 15 at 2:56
    
well it easy to say possible, have you experience doing this? i tried do it myself but failed so i was confirming if it is possible or has anyone done this and i also mentioned that i can do append in the backend using acf any reference would be helpful though onhow to append user meta data in the front end usually you do this <?php add_user_meta( $user_id, $meta_key, $meta_value, $unique ); ?> well that only adds value to an existing meta or update it what i am trying to achieve is append data –  JPL Jun 15 at 4:14

1 Answer 1

Use the project name in the meta key field & the amount donated as the meta value, and I would suggest using update_user_meta rather than add_user_meta because reasons. Something like this:

$project = 'donated_to_' . $project;    
update_user_meta( $user_id, $project, $amount );

Apply some sort of logic before setting those variables - you know, in case the user has previously donated to that project.

The function update_user_meta is available on the front end and as for security, use a nonce on the form where you're collecting this data and check the nonce & user permissions on processing of the form and verify/sanitize the data received from that form during variable assignment.

share|improve this answer
    
no problem with updating an existing user_meta, but what i am trying to do is add a user meta based on the project in the front end e.g. the post type name is My First Project and use donated to that project, how would you add my first project in your user meta and say the amount donated to that project. Another example would be i have over 100 projects and each project has a donation form and when a user donate to each project each project will be added to user meta with the equivalent amount –  JPL Jun 16 at 17:56
    
Directly quoted from the documentation: "If the meta field for the user does not exist, it will be added." codex.wordpress.org/Function_Reference/update_user_meta –  Will the Web Mechanic Jun 16 at 18:21

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.