Skip Navigation

[Resolved] Change Post Status Draft/Publish of Product on the frontend

This support ticket is created 6 years, 5 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
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9: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/Hong_Kong (GMT+08:00)

This topic contains 11 replies, has 2 voices.

Last updated by Luo Yang 6 years, 4 months ago.

Assisted by: Luo Yang.

Author
Posts
#919744

Hi,

I am trying to follow this instruction here but this doens't work! : https://toolset.com/forums/topic/change-draft-to-publish-using-button/

1- I have changed the Cred form submission status to Keep original status

2- i have added generic field to the toolset product form:

[cred_generic_field field="post_status" type="radio" class="" urlparam=""]
{
"required":0,
"validate_format":0,
"default":["publish"],
"options":[
{"value":"draft","label":"Draft"},
{"value":"publish","label":"Publish"}
]
}
[/cred_generic_field]

3- then i have added the function to my code snippet:

// CRED PUBLISH STATUS
add_action('cred_save_data_67', 'Select_Post_Status_func',10,2);
function Select_Post_Status_func($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 );
}
#920145

Hello,

In your custom PHP codes, you need to replace number "67" with your Toolset form ID, more help:
https://toolset.com/documentation/programmer-reference/cred-api/#cred_save_data

#920561

AWESOME LUO! it works now.

just would like to know if its possible to keep the original status of the post if used didnt use a status.

i have added this code:

[cred_generic_field field='post_status' type='select' class='' urlparam='']
      {
      "required":0,
      "validate_format":0,
      "default":[""],
      "options":[
      {"value":"publish","label":"Publish"},
      {"value":"draft","label":"Draft"},
      {"value":"pending","label":"Pending"}
      ]
      }
      [/cred_generic_field]

and as wll this function:

// CRED PUBLISH STATUS
add_action('cred_save_data_103', 'Select_Post_Status_func',10,2);
function Select_Post_Status_func($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 );
}

my cred form has Keep Original Status on.

but when i edit a published post it doesn't pull the current status of the post and if i submit the form, the post will be drafted. the best solution to make it required field but is it possible to show the current post status in the field? instead to select the status option everytime?

#920621

Yes, you can modify this line from:

$my_post['ID'] = $post_id;

To:

if($_REQUEST['post_status'] == ''){
//Do nothing
return;
}
$my_post['ID'] = $post_id;
#920973
// CRED PUBLISH STATUS
add_action('cred_save_data_103', 'Select_Post_Status_func',10,2);
function Select_Post_Status_func($post_id) {
if($_REQUEST['post_status'] == ''){
//Do nothing
return;
}
$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 added this but still no value assigned as post status when editing the form.

#921059

Please try this, the from shortcode as below:

[cred_generic_field field="post_status" type="radio" class="" urlparam=""]
{
"required":0,
"validate_format":0,
"default":["[wpv-post-status]"],
"options":[
{"value":"draft","label":"Draft"},
{"value":"publish","label":"Publish"}
]
}
[/cred_generic_field]

Setup the "default" value as current post status [wpv-post-status].

More help:
https://toolset.com/documentation/user-guides/cred-shortcodes/#cred_generic_field

#922826

I will test this soon!

#922887

OK, please update this thread if you still need assistance.

#948202

I will reply after 18.07

#948270

OK, waiting for you update.

#951374

Awesome this has solved it! Thank Luo

#951661

You are welcome