Skip Navigation

[Resuelto] redirect to a parent post after adding/editing a child post from a post form

This support ticket is created hace 5 años, 3 meses. 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
8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 - -
13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 - -

Supporter timezone: America/New_York (GMT-04:00)

Etiquetado: ,

Este tema contiene 1 respuesta, tiene 2 mensajes.

Última actualización por Christian Cox hace 5 años, 3 meses.

Asistido por: Christian Cox.

Autor
Mensajes
#1318343

I'm really struggling to figure out how to make a form for a child post redirect to its parent after submission. There are a few solutions in the forum but I just can't get them to work properly.

Here's my code:

<?php

toolset_snippet_security_check() or die( 'Direct access is not allowed' );

add_filter('cred_success_redirect', 'redirect_to_parent', 10, 3);
function redirect_to_parent($url, $post_id, $form_data) {
if ($form_data['id']==2873 || $form_data['id']==2896) {
$parent_id = toolset_get_related_post($post_id, 'work-recording');
$url = get_permalink( $parent_id );
if ($form_data['id']==3157 || $form_data['id']==3162) {
$parent_id = toolset_get_related_post($post_id, 'work-resource');
$url = get_permalink( $parent_id );
}
}
return $url;
}

My Work post type is the parent, and then I have Recording, Resource and Lyric and child post types. I want to redirect to the Work when I add or edit a child post type.

#1318569

Hi, in the Form editor screen for these 4 Forms, the option "After visitors submit this form" must be set to "Go to a specific post" or "Go to a page". It doesn't matter which post or page is selected here, but some redirect must be set. Otherwise the redirect hook will not be triggered.

If that doesn't solve the problem, we should add some server log statements and monitor the logs to see what is happening. If you're not familiar with server logs, I can show you how to activate them temporarily. Go in your wp-config.php file and look for

define('WP_DEBUG', false);

Change it to:

define('WP_DEBUG', true);

Then add these lines, just after the WP_DEBUG line:

define('WP_DEBUG_LOG', dirname(__FILE__) . '/error_log.txt');
define( 'WP_DEBUG_DISPLAY', false );
@ini_set( 'display_errors', 0 );

Submit the Form, and a new file should be created in the root directory of your site called "error_log.txt". Open the log in any text editor, copy the contents, and paste them in your next reply. When we are done testing you can revert the changes in wp-config.php and delete the log.