Navigation überspringen

[Gelöst] pass newly created post id with url parameter to target page

Dieser Thread wurde gelöst. Hier ist eine Beschreibung des Problems und der Lösung.

Problem: I would like to use the Forms API to redirect to a specific URL, including a parameter set by the new post ID.

Solution: The second parameter in the callback function, $post_id, contains the ID of the created or edited post.

add_filter('cred_success_redirect', 'custom_purchase_redirect',10,3);
function custom_purchase_redirect($url, $post_id, $form_data)
{
  if ($form_data['id']==60) {
    $redirect = $url . "?fit=" . $post_id;
    return $redirect;
  }
  return $url;
}

Relevant Documentation:
https://toolset.com/documentation/programmer-reference/cred-api/#cred_success_redirect

This support ticket is created vor 6 Jahren. 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
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)

Dieses Thema enthält 2 Antworten, hat 2 Stimmen.

Zuletzt aktualisiert von Ido Angel vor 6 Jahren.

Assistiert von: Christian Cox.

Author
Artikel
#1193975

hey,
i have a cred form where the user submit a new "company", then is being redirected to an inner payment page on the site.
I wanted to add to the payment form (a stripe form, not cred) a unique id equal to the id of the newly created company. But I only managed to get a custom field, and not the new company post id.

My code:

add_filter('cred_success_redirect', 'custom_purchase_redirect',10,3);
function custom_purchase_redirect($url, $post_id, $form_data)
{
  if ($form_data['id']==60) {
    $companyid = get_post_meta( $post_id, 'wpcf-company-name', true );
    $redirect = $url . "?fit=" . $companyid;
    return $redirect;
  }
  return $url;
}

My jQuery to populate the stripe form input field:

jQuery(document).ready(function( $ ){
	var str = window.location.href;
  var credReferrer = str.match("fit=(.*)&cred_referrer_form_id");
  $(".wpfs-payment-form .control-group input[id='fullstripe-custom-input__fitness-inline-01__1']").val(credReferrer[1]);
});

I tried using "wpv-post-id" instead of "wpcf-company-name", but that resulted in nothing.

Any chance of getting this done somehow? I know the notification email sent after the cred submission CAN include the new post id.

thanks!

Ido

#1193976

Hey the second parameter, $post_id, in the cred_success_redirect callback is the ID of the post that was just created or edited. You're already using it to get the post meta value, but that's not necessary. You can just use $post_id directly instead:

add_filter('cred_success_redirect', 'custom_purchase_redirect',10,3);
function custom_purchase_redirect($url, $post_id, $form_data)
{
  if ($form_data['id']==60) {
    $redirect = $url . "?fit=" . $post_id;
    return $redirect;
  }
  return $url;
}

Let me know if I misunderstood what you're trying to accomplish.

#1193987

My issue is resolved now. Thank you! Perfect as always, Chris!!