Skip Navigation

[Resolved] Redirect to parent post after adding child using cred

This thread is resolved. Here is a description of the problem and solution.

Problem:

Get related parent post ID in custom PHP codes.

Solution:

In the latest version of Toolset plugins, you need to use Types API function toolset_get_related_post() to get the parent post information, for example

https://toolset.com/forums/topic/redirect-to-parent-post-after-adding-child-using-cred/#post-2218137

Relevant Documentation:

https://toolset.com/documentation/customizing-sites-using-php/post-relationships-api/#toolset_get_related_post

This support ticket is created 3 years, 1 month ago. 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.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9: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/Hong_Kong (GMT+08:00)

This topic contains 2 replies, has 2 voices.

Last updated by jamesR-13 3 years, 1 month ago.

Assisted by: Luo Yang.

Author
Posts
#2217849

I am trying to use cred_success_redirect redirect the user back to a parent post after they have submitted a child post using a cred form. The parent post type is "Service Request" the slug is 'service-request" Here is my code:

//redirect to parent after adding address
add_filter('cred_success_redirect', 'custom_redirect',10,3);
function custom_redirect($url, $post_id, $form_data)
{
    if ($form_data['id']==121)
        $parent_id = get_post_meta($post_id, '_wpcf_belongs_service-request_id', true);
        $permalink = get_permalink('$parent_id');
        return $permalink ;
    return $url;
}

The form still seems to abide by the option selected in the gui i.e. "Display a message" or "display the post" rather than redirecting per the code above. What am I missing?

#2218137

Hello,

In the latest version of Toolset plugins, you need to use Types API function toolset_get_related_post() to get the parent post information, for example, replace this line of your PHP codes from:
$parent_id = get_post_meta($post_id, '_wpcf_belongs_service-request_id', true);

With:
$parent_id = toolset_get_related_post( $post_id, 'service-request' );

Please replace "service-request" with the post type relationship slug

More help:
https://toolset.com/documentation/customizing-sites-using-php/post-relationships-api/#toolset_get_related_post

#2223365

My issue is resolved now. Thank you!