Tell us what you are trying to do?
Hi there,
I'm trying to setup a redirection to previous post on form submit. I guess I need to use a custom hook for this? I see in the docs there's an example -
//This filter can also be applied for a specific form, using the form ID:
add_filter('cred_success_redirect_12', 'custom_redirect_for_form_with_id_12', 10, 3);
function custom_redirect_for_form_with_id_12( $url, $post_id, $form_data )
{
$newurl = 'lien caché';
return $newurl;
}
The form in question is a child edit form(CPT comment) and it's parent id (CPT member) is parsed from the previous post. So I want to know how I can use this parent ID in the webhook to redirect it back after form submit?
Something like -
$newurl = 'lien caché ';
Any help appreciated, thank you!
Hi Tom,
Thank you for getting in touch.
Does the URL to the form has the Parent ID in the url already?
Please let me know.
Thanks,
Shane
No not parent post id but it does have the comment title in the url.
e.g. lien caché
Within the form I have a hidden field set as:
Default slug: @member-comment.child
Default field value: [wpv-post-id]
The url to the form is a link with a parent member loop using this shortcode:
[toolset-edit-post-link content_template_slug='edit-comment' target='self']Edit comment[/toolset-edit-post-link]
Thanks,
Tom
Hi Tom,
Thank you for the information.
Would you mind allowing me to have admin access to the website so that I can have a more detailed look at this for you ?
Please me with a link to where I can navigate to the child post form.
I've enabled the private fields for your next response.
Thanks,
Shane
Hi Tom,
You can use this to get the parent post id.
add_filter('cred_success_redirect', 'custom_redirect',10,3);
function custom_redirect($url, $post_id, $form_data)
{
$parent_id = get_the_ID();
if ($form_data['id']==368)
return '<em><u>lien caché</u></em>';
return $url;
}
Note i've added the $parent_id variable that gets the ID of the current post. You will see this function in Toolset -> Settings -> Custom Code.
All that's needed is for you to add the redirection URL and include the $parent_id variable in the url.
Thanks,
Shane
Thank you so much I really appreciate your help!
I notice the form_data ID in the code is for the New comment form not the Edit comment form? I changed the ID to 434 but either way it's not actually redirecting me after submit. Did it work for you?
Hi Tom,
Thank you for the clarity.
The problem that we are encountering now is that there isn't a way for me to get the parent id unless you've added the relationship field to the edit form.
I can go ahead and do this and then restructure the code to work with the parent field but please let me know if this is ok.
Thanks,
Shane
Hi Shane
That sounds great thank you!
Can the relationship field can be hidden on front end? If so please go ahead. Thank you.
Hi Tom,
This should now be working.
Thanks,
Shane
Thank you Shane.
The member id is in the url after forum submit but the redirect still doesn't work properly. It doesn't redirect to single member but all members.
Is this because id and not slug in the url? lien caché.
Hi Tom,
I misinterpreted, you want it to redirect to the member that you're editing the comment for ?
Please let me know .
Thank,
Shane
"I misinterpreted, you want it to redirect to the member that you're editing the comment for ?" Yes exactly that.
Thank you Shane.
Hi Tom,
I've made an adjustment to the code and it works now.
Thanks,
Shane
That's it! My issue is resolved now. Thank you Shane.