Skip Navigation

[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.

Sun Mon Tue Wed Thu Fri Sat
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10: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/Kolkata (GMT+05:30)

Este tema contiene 11 respuestas, tiene 2 mensajes.

Última actualización por Minesh hace 7 años.

Asistido por: Minesh.

Autor
Mensajes
#590020

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?

#590234

Minesh
Supporter

Idiomas: Inglés (English )

Zona horaria: Asia/Kolkata (GMT+05:30)

Hello. Thank you for contacting the Toolset support.

As I understand, you would like to have field to edit current page slug inside your CRED form - correct?

#590297

Correct, that's what I need please!

#590559

Minesh
Supporter

Idiomas: Inglés (English )

Zona horaria: Asia/Kolkata (GMT+05:30)

Well - basically for such cases you can add CRED generic field to your CRED form and use it as per your requirement.

More info:
=> https://toolset.com/documentation/user-guides/inserting-generic-fields-into-forms/

And later, use CRED hook, CRED save data to update the slug for your post/page:
=> https://toolset.com/documentation/programmer-reference/cred-api/

#590653

Ok, thank you. I'm following your instructions but I'm not a programmer. Could you lend me a hand with the code please?

This is what I have at CRED form:

<div class="cred-field">
<label class="cred-label">Page URL</label>
[cred_generic_field field='post_slug' type='textfield' class='' urlparam='']
{
"required":0,
"validate_format":0,
"default":""
}
[/cred_generic_field]
</div>

And this is the code at functions.php:

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);
}
}
}

#591197

Minesh
Supporter

Idiomas: Inglés (English )

Zona horaria: Asia/Kolkata (GMT+05:30)

Ok - I'm happy to help you further.

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.

#591559

Minesh
Supporter

Idiomas: Inglés (English )

Zona horaria: Asia/Kolkata (GMT+05:30)

Could you please tell me where you added the CRED edit form "Sections Content"? Could you please share link of that page.

#591732
form-link.jpg

Sure, for example it's at homepage enlace oculto.

You will see a blue button in the top right corner (sorry before it was hidden under the toolbar for admin user).

The shortcode it's at the layout "Home Pages Layout".

#592047

Minesh
Supporter

Idiomas: Inglés (English )

Zona horaria: Asia/Kolkata (GMT+05:30)

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:

[cred_generic_field field='post_slug' type='textfield' class='' urlparam='']
{
"required":0,
"validate_format":0,
"default":"[get_slug]"
}
[/cred_generic_field]

Could you please confirm it works for you as well.

#592065

Thanks Minesh, it's working great!

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).

#592123

Sorry I closed the ticket by mistake.

Thanks Minesh, it's working great!

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).

#592124

Minesh
Supporter

Idiomas: Inglés (English )

Zona horaria: Asia/Kolkata (GMT+05:30)

Could you please open a new ticket for your each new question. This will help other users searching on the forum. Thank you for understanding.