Skip Navigation

[Resolved] Linking multiple posts to a post in one-to-many relationship from the frontend

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

Problem:

The problem here is that the user is using the redirect settings on their form to reload the page that the form is on after it has been submitted, however instead of reloading the page they're redirected to the homepage.

Solution:

This is happening because the user is using the default permalink settings for wordpress instead of the postname permalink settings.

In order for the redirect to work correctly then you must use the postname permalink settings.

This support ticket is created 3 years, 2 months 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 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 -
- 13:00 – 18:00 13:00 – 18:00 13:00 – 18:00 14:00 – 18:00 13:00 – 18:00 -

Supporter timezone: America/Jamaica (GMT-05:00)

This topic contains 16 replies, has 2 voices.

Last updated by igorL-3 3 years, 2 months ago.

Assisted by: Shane.

Author
Posts
#2190783

Tell us what you are trying to do?

This is what I want to do. I have Custom Types: MEETINGS, PEOPLE and one-to-many relationship called ATTENDEES between MEETINGS and PEOPLE. I have a Post Form for MEETINGS where one fills out the Title, Date and Agenda and after submission I display the post. But I now what to link ATTENDEES to each meeting. As ATTENDEES is a one to many I have a relationship form that I have placed on the Content Template for MEETINGS. But each MEETING can have more than one ATTENDEE but I’m not sure how to set that up. I tried to select Reload Page after submission for the relationship form but that always goes back to the HOME page. I’d be grateful for the help how to set it up so that multiple PEOPLE can be linked to each meeting as ATTENDEES.

Is there any documentation that you are following?

Is there a similar example that we can see?

What is the link to your site?

#2191083

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Igor,

Thank you for getting in touch.

Are you saying that after you've linked an ATTENDEE to a meeting and reload the page to link more ATTENDEES you're not able to and just get redirected to the homepage?

Would you mind allowing me to have admin access to the site so that I can have a more detailed look at this for you.

Thanks,
Shane

#2192193

Sure,
Please send me a secure request

#2193011

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Igor,

Here are the private fields.

Thanks,
Shane

#2193933

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Igor,

I see the issue.

The problem is because the post isn't published. For the form to redirect to the correct page the post that is created must be published.

As soon as I set my meeting to be published then i'm able to add the other user posts and redirect to the page correctly.

Thanks,
Shane

#2194099

That didn't work for me. I tried setting "Set this post status:" to Published in the post form or just going directly from the link of the published post from the backend. In all cases after clicking SUBMIT after the post linking on the displayed post it forwards to /?cred_referrer_form_id=296501

I even tried with the post you created /?board-meeting=test-meeting and it too forwarded to ?cred_referrer_form_id=296501 which takes it to the home page.

So I'm not sure how you did what you said?

#2194181

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Igor,

Your Post Form that created the Board Meeting is setting the post status to Pending. This means the post isn't published. Try going to your Post Form and changing the status to submit the posts as published.

Alternatively you can manually go to the posts on the backend and publish the post from the post edit screen.

Please let me know if this is clear.

Thanks,
Shane

#2194255

But that's exactly what I did as I explained in the above post.

#2194259

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Igor,

Please try now i've made a few adjustments. I've also changed your permalink settings to use the postname instead of the post ID.

The form is also set to publish the meeting as well.

Thanks,
Shane

#2194265

Yes that way it did work. But I need the permalink to work with the id becouse I have quite a bit of custom code alredy that relies on the id. Can this be made to work with the id?

#2194305

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Igor,

You will quite possibly need to create a custom redirect for it to work correctly.
https://toolset.com/documentation/programmer-reference/cred-api/#cred_success_redirect

Try this below.

add_filter('cred_success_redirect', 'custom_redirect',10,3);
function custom_redirect($url, $post_id, $form_data)
{
    if ($form_data['id']==12)
        return get_permalink();
   
    return $url;
}

Change the 12 to the actual ID of your form i.e your relationship form.

Thanks,
Shane

#2194889

Hello Shane,

I've been trying to get cred_success_redirect to work. But I don't think this filter is called for the SUBMIT when linking posts through a relationship. It is called for the create meetings form but not for the link users form. Is there another filter/hook? Is it possible to set the submit and redirect without using the [cred-form-submit] shortcode? Are there additional parameters in [cred-form-submit] shortcode that can be set directly?

To check that cred_success_redirect is called a set the follwing condition:

if ($form_data['id']==$fr_id {
return 'hidden link';
}

where $fr_id is 296501 (link site users form) or 296497 (create new meeting form)

As per cred_success_redirect documentation I set the redirect on 296501 (link site users form) to a page About Us. When $fr_id=296497 the redirect goes to google as expected but when it's equal to 296501 it goes to About Us. Unless the id is not 296501 but I checked it and it seems correct therefore I don't understand why there is no redirection through cred_success_redirect!!!

#2195207

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Igor,

I've tested quite a few possibilities to get this to work.

It won't be possible to achieve with your current setup. I've tried the following hook
https://toolset.com/documentation/customizing-sites-using-php/post-relationships-api/#toolset_association_created

This hook is fired when a relationship is created and it works for the most part but the form is still taking priority.

Thanks,
Shane

#2195239

Thank you Shane.

Seems like it's a bug. Is there likely to be a patch or an update to correct this?

#2199741

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Igor,

I dont believe this one is a bug. It could just be a case where the hook doesn't function with the Relationship forms and its only meant to work for Post Forms.

What I can do is to double check with our 2nd tier team to get a different perspective on the hook and let you know. I will provide an update as soon as I get a response.

Thanks,
Shane