I am trying to:
Update Post status with drop-down on front-end form as seen in this thread
https://toolset.com/forums/topic/change-post-status-draft-publish-of-product-on-the-frontend/
My form is set to "Keep original status"
I have implemented the following on the form (id= 1230)
<div class="status">
<label>Profile Status</label>
[cred_generic_field type='select' field='post_status']
{
"required":0,
"default":["[wpv-post-status]"],
"options":[{"value":"publish","label":"Publish"},{"value":"draft","label":"Draft"}]
}
[/cred_generic_field]
</div>
And the following custom code snippet:
// CRED PUBLISH STATUS
add_action('cred_save_data_1230', 'custom_select_post_status',10,2);
function custom_select_post_status ($post_id) {
$my_post['ID'] = $post_id;
$my_post['post_status'] = $_REQUEST['post_status'];
// Update the post into the database
wp_update_post( $my_post );
}
I have cleared my server and browser cache and it still won't work. Am I missing something?
Hi, the same code works for me with a different Form ID, so something else must be going on. How are you adding this custom code, in your child theme's functions.php file, or in a custom code snippet in Toolset > Settings > Custom Code? Can you try disabling other non-Toolset plugins temporarily?
Hi Christian,
I am using Toolset > Settings > Custom Code.
I have cred_save_data working with another form ID, just not this one.
I don't really have a lot of time to troubleshoot this, and the page the form is on won't render if I turn off elementor (only other plugin that is live), and I don't really want to build a test page lol.
I am going to change my publishing flow for users so that it always puts the post in draft after update, and they have to publish from the preview page using another cred form that is just a single button to publish.
Just wanted to see if my code was the issue. I will test in the future when I have time.
You can close the ticket.
Cheers,
Cam.
My issue is resolved now. Thank you!