[Resuelto] Cred_field for editing page slug from the front end with CRED form
This support ticket is created hace 7 años. 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.
Hoy no hay técnicos de soporte disponibles en el foro Juego de herramientas. Siéntase libre de enviar sus tiques y les daremos trámite tan pronto como estemos disponibles en línea. Gracias por su comprensión.
I am trying to add a field at the content editor CRED form to change (from the front end) the slug of the current page where the form is been displayed . With the "auto generat form" it only show the title, featured image, body, etc fields to edit.
Is that possible?
add_action('cred_save_data', 'my_save_data_action',10,2);
function my_save_data_action($post_id, $form_data)
{
// if a specific form
if ($form_data['id']==109)
{
if (isset($_POST['post_slug']))
{
// add it to saved post meta
add_post_meta($post_id, 'post_slug', $_POST['post_slug'], true);
}
}
}
Could you please share problem URL where you've added CRED form and information which slug we need to allow user to change using CRED form field post_slug?
*** 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 would additionally need your permission to de- and re-activate Plugins and the Theme, and to change configurations on the site. This is also a reason the backup is really important. If you agree to this, please use the form fields I have enabled below to provide temporary access details (wp-admin and FTP).
I have set the next reply to private which means only you and I have access to it.
Could you please check now. I've added following code to your current theme's functions.php file.
// to update the post slug
add_action('cred_save_data', 'func_change_post_slug', 10, 2);
function func_change_post_slug($post_id, $form_data){
if ($form_data['id']==109) {
$slug = sanitize_title($_POST['post_slug']);
wp_update_post(array('ID'=>$post_id,'post_name' => $slug));
}
}
// to get the value of post slug
add_shortcode( "get_slug","func_get_slug");
function func_get_slug($post_id, $form_data){
if (isset($_GET['_id']) and $_GET['_id']!='' ) {
$id = $_GET['_id'];
$post = get_post($id);
return $post->post_name;
}
}
And in your CRED form I've adjusted the CRED generic field as given under to assign default value using shortcode:
Just one doubt, in arabic language (ex. enlace oculto) the page slug is been saved ok but when I edit the page with CRED form the page slug changes to a code of simbols and numbers. Could this be resolved? To show the correct page slug in arabic at the CRED form field. It's not afecting the functionality of the page slug but it's not practic for translators that have access only to the front-end (at WP back-end the permalink field shows the slug in arabic).
Just one doubt, in arabic language (ex. enlace oculto) the page slug is been saved ok but when I edit the page with CRED form the page slug changes to a code of simbols and numbers. Could this be resolved? To show the correct page slug in arabic at the CRED form field. It's not afecting the functionality of the page slug but it's not practic for translators that have access only to the front-end (at WP back-end the permalink field shows the slug in arabic).