Redirect to parent post after editing Repeatable Field Group (RFG) in Forms

In this example, we have a repeatable field group (RFG) assigned to some custom post type. On the single post page, we are showing a View of the RFG related to the current post. We want to give some Users the ability to edit those RFGs on the front-end using Forms. In the current system, the recommended approach is to use an Edit Post link in the View to send the User to a page containing a Form. This can be a tedious workflow if you must edit multiple RFGs, going back and forth from the parent post to the Form editor. This code snippet can be used to automatically redirect the User to the post containing the RFG, saving one step in the process. Note that you must set the Form to redirect to some existing Page in the Form configurations. Otherwise, the redirect code will not have any effect on the Form.

/* ----------------------------------------------------------------------- */
// REDIRECT TO RFG PARENT POST AFTER EDITING RFG IN FORMS
// After submitting edit RFG Form, redirect to the post containing the RFG
// Be sure to set some redirect in wp-admin for this Form
//
add_filter('cred_success_redirect', 'custom_redirect_rfg_editor',10,3);
function custom_redirect_rfg_editor($url, $post_id, $form_data)
{
  $forms = array( 12345 );
  $rfg_slug = 'your-rfg-slug';
  if ( in_array( $form_data['id'], $forms ) ) {
    $parent_id = toolset_get_related_post( $post_id, $rfg_slug );
    return get_permalink($parent_id);
  }
  return $url;
}

Let us know if this snippet is not working for you:

This snippet doesn’t work
0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Inline Feedbacks
View all comments