Skip Navigation

[Resolved] update the author of a post with the current login user at fornt-end

This support ticket is created 4 years, 6 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Kolkata (GMT+05:30)

This topic contains 4 replies, has 2 voices.

Last updated by Minesh 4 years, 6 months ago.

Assisted by: Minesh.

Author
Posts
#1940439
image-toolset.png

I am creating a custom php code to assign orders to employees.
I have created a custom field in orders with name employee-username to store the user id of the
employee.
I also created a form to get the current login user:

[credform class="employeeBox"]
[cred_field field='employee-username' force_type='field'
class="employeeName" Value='[wpv-current-user info="login"]'
output='bootstrap']
[cred_field field='form_submit' output='bootstrap' class="employeeBtn"
value='Get This Order']
[/credform]

I used custom php to display the form I created (screenshot attached)

but when I click (Get This Order) the field doesn't get updated:
here is my php line:

echo cred_form('assignEmployee', $order->get_id());

here is my function in function.php

add_action('cred_save_data' , 'assignEmployee_action',10,2);
function assignEmployee_action($order_id, $form_data){
if($form_data[id]==18){
update_post_meta( $order_id, 'wpcf-exeutor-
username',$_POST['exeutor-username'] );
}
}

Am I missing something?

#1940717

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hello. Thank you for contacting the Toolset support.

I would like to know, you have a Edit post form to update the existing order value - correct?

If yes, it seems there is some issue with the code you shared but I'll be able to tell better when I can able to review your existing setup and for that I will require admin and FTP access detaials.

Can you please share on what page/post you added the Toolset form using the function cred_form()?

*** Please make a FULL BACKUP of your database and website.***
I would also eventually need to request temporary access (WP-Admin) to your site. Preferably to a test site where the problem has been replicated if possible in order to be of better help and check if some configurations might need to be changed.

I have set the next reply to private which means only you and I have access to it.

#1942025

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

First of all - After checking to debug the information you shared with us, I found that you are using outdated Toolset plugins. We always recommend running your site with the latest stable release plugin version.

*** Please make a FULL BACKUP of your database and website.***
Could you please update ALL Toolset plugins to it's latest officially released version. You can download the latest plugin release from your accounts page:
=> https://toolset.com/account/downloads/

Once ALL Toolset plugins updated to latest release,

I checked the functions.php file and I can see that now you adjust the code there as given under where you changed the update_post_meta() to add_post_meta():

add_action('cred_save_data' , 'assignEmployee_action',10,2);
function assignEmployee_action($post_id, $form_data){
    
    if($form_data[id]==185){
   	 console.log("This is msg from form 18");
   	 if(isset($_POST['emplyee-username'])){
   		 console.log($_POST['emplyee-username']);
   		 add_post_meta($post_id,'wpcf-emplyee-username',$_POST['emplyee-username'],true);
   		 //update_post_meta( $order_id, 'wpcf-exeutor-username',$_POST['exeutor-username'] );
   	 }
   	 
    }
}	

I would like to inform you that Toolset offers "Custom Code" section that you can use to add your custom code so you will not have to interact with theme files.
=> https://toolset.com/documentation/adding-custom-code/using-toolset-to-add-custom-code/

I suggest you should move your code to "Custom Code" rather using theme file.

now, do you see your issue is fixed? or do you need further help? if yes, please clarify what is not working exactly.

#1942761
unnamed (1).png

Thank you for your help,

My issue is not yet solved, I moved my custom code to where you suggested.
Whenever I click :Get this order" in ( hidden link ) it creates new empty orders, it will not update the custom value field.

#1943337

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

I checked and I can see that you are using the following form within the neworders custom shortcocde you added:
- hidden link

The above form is set to "Add new content " that is why its creating the new entry. I changed the "Form type" to "Edit existing content" and when I click on Get button I can see now that the username is updated.

In addition to that, I'm not sure why you created custom shortcode to display the orders as you can also query the orders by creating the view but there must be some reason behind that you created custom shrotcode.