admin - How to save edited post when submitting form

admin2025-06-03  4

I have added a custom button(via form in html) on my WooCommerce edit product(same as WordPress edit past I think) page. When this button is pressed, my php code will parse the post content. The problem is that if I edit the post content, and do not first click the standard "Update" button, my edited content is lost. How can I add the standard WordPress "Update" button functionality to my custom form button?

This is my form I added, using the "add_meta_box" action:

<form method="post" action="">
<div>
<input type="submit" name="mxUpldImg" class="button-primary" alue="Upload Mx Img" />
</div>
</form>

I then check for my post using the "admin_init" action.

I have added a custom button(via form in html) on my WooCommerce edit product(same as WordPress edit past I think) page. When this button is pressed, my php code will parse the post content. The problem is that if I edit the post content, and do not first click the standard "Update" button, my edited content is lost. How can I add the standard WordPress "Update" button functionality to my custom form button?

This is my form I added, using the "add_meta_box" action:

<form method="post" action="">
<div>
<input type="submit" name="mxUpldImg" class="button-primary" alue="Upload Mx Img" />
</div>
</form>

I then check for my post using the "admin_init" action.

Share Improve this question asked Feb 4, 2019 at 6:08 davidaudavidau 1
Add a comment  | 

1 Answer 1

Reset to default 0

What are you doing in the parsing function of the post content? You can do the same thing on the trigger of the standard update button to avoid data loss.

Please use the save_post hook to perform your function on the click of the standard update button. Please see the below link for documentation of save_post hook. https://codex.wordpress/Plugin_API/Action_Reference/save_post

转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1748946453a315056.html

最新回复(0)