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 );
}
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
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?
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;
// 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.
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
OK, please update this thread if you still need assistance.
OK, waiting for you update.
Awesome this has solved it! Thank Luo