add_action('cred_save_data', 'set_chart_visibility',10,2);
function set_chart_visibility($post_id, $form_data) {
// Check that this is the correct form.
if ($form_data['id'] != 161917) {
return;
}
// Get the value of the dropdown.
$visibility = $_POST['chart_visibility'];
// Set the post status.
if ($visibility == 'public') {
$post_status = 'publish';
} else {
$post_status = 'private';
}
// Update the post.
wp_update_post(array(
'ID' => $post_id,
'post_status' => $post_status,
));
}
This works well however, I need help setting the option value as the actual option rather than the default value? Any ideas how?
I've read through your code and I see what you are trying to do.
But I'm not sure what you need help with, I don't follow what you mean by "setting the option value as the actual option rather than the default value".
I'm trying to create a drop down for the user to decide whether the post is public or private. I'm trying to figure out how to set the current status when loading the page.
For example, if the post is set to publish the drop down will load as published etc.
Do you have post edit form or post form to create new entry?
Can you please share problem URL where you added your form as well as admin access details?
*** Please make a FULL BACKUP of your database and website.***
I would also eventually need to request temporary access (WP-Admin and FTP) to your site. Preferably to a test site where the problem has been replicated if possible in order to be of better help and check if some configurations might need to be changed.
I have set the next reply to private which means only you and I have access to it.
The topic ‘[Closed] Public/Private post drop down’ is closed to new replies.