Skip Navigation

[Resolved] Trying to Update Post status with drop-down on front-end form

This support ticket is created 5 years 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
8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 - -
13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 - -

Supporter timezone: America/New_York (GMT-04:00)

This topic contains 3 replies, has 2 voices.

Last updated by mikaelD 5 years ago.

Assisted by: Christian Cox.

Author
Posts
#1376495

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?

#1376679

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?

#1376739

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.

#1376741

My issue is resolved now. Thank you!