Skip Navigation

[Closed] New Posts Created With Toolset Forms Not Connecting To Parent

This support ticket is created 4 years 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
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)

Author
Posts
#1878519
No connections.PNG
Capture.PNG

I am trying to: Update Toolset

I updated Toolset plugins to the newest versions, but now I am experiencing an issue. Usually when creating a post with a Toolset Form, the child post created will automatically connect to the parent post. However, after updating Toolset, new posts no longer connect to the parent post.

I have a parent post called "fair". Each time a "booth" post is created, it should become a child of the parent fair post, but this does not seem to happen. On the booth post, instead of displaying a link to the parent fair post, it displaying a link to the same post. When checking the editor, it does not seem that they are connected.

I tried to use a default WordPress Theme and deactivated all other plugins, but this did not seem to fix the issue.

Link to a page where the issue can be seen: hidden link

Plugin Versions Prior To Update:

Toolset Access Version 2.8.7

Toolset Forms Version 2.5.8

Toolset Layouts Version 2.6.5

Toolset Types Version 3.3.13

Toolset Views Version 3.2.2 |

How to replicate the issue:

1. Go to hidden link
2. Use the form: hidden link
3. The booth will not be connected to the parent fair (test-fair-12-16)

#1878573

Hi, our developers are working on a hotfix that addresses a similar issue in child post forms where the parent select field isn't working as expected. A patch has been issued here to address that: https://toolset.com/errata/parent-post-selector-in-edit-post-form-not-working-correctly/

I'd like to see if this patch solves the problem here, since they seem to be closely related. Can you apply the patch using the instructions in the erratum post and let me know if the problem is resolved? Note that the solution does not retroactively fix child posts that were already created, it only fixes new child posts and existing child posts that are created/edited with Forms after applying the patch.

#1880507

Hi Christian,

I tried downloading Forms 2.6.5 (which I think the post says addresses that issue), but it doesn't seem to have fixed the issue I am experiencing. I noticed that in the Toolset dashboard that there is an update for the database
"Toolset needs to update the database. This will take a few minutes to complete."

Before going ahead and running that and making things more complicated, I wanted to see if you thought issue might be that I need to update the database (just incase that is not the issue and causes other issues).

#1881595

To be sure, I can log into your site and install the Duplicator plugin to create a site clone. Then I can run the database upgrade on a copy of your site locally, to see if the issue is resolved or if there is something else going on. Let me know if you approve and I can get started.

#1882913

That would be great. In the initial ticket, I added a link to a Duplicator package, but I can add it again if needed.

#1884153

I'm still investigating this, but it appears that a temporary workaround would be to add the fair_booth relationship field into the New Booth Form- Day1 Form contents. This will create a parent post select field in the Form contents and populate that field with the correct parent Fair selected by the URL parameter. To hide the field from the front-end User, you can add two custom HTML blocks to the Form contents, one above the fair_booth field and one below the fair_booth field.

In the first custom HTML block, add the following code:

<div style="display:none;">

In the second custom HTML block, add the following code:

</div>

This will effectively hide the parent Fair field on the front-end, since it is being populated automatically and you don't want the User to be able to change it.

I'll keep you posted as I continue the investigation, but wanted to present a temporary solution now.

#1884185

I don't think the Toolset database upgrade message is related here, and I don't think it will solve the problem. I'm not exactly sure how this child post setup would have been working correctly before, unless there was some remnant from a migrated legacy post relationship at play. As a test, in a site I created from scratch, I installed the older versions of Types, Views and Forms that were present on your site and created a O2M post relationship between two post types. I created a new child post Form that did not include the post relationship field. I created a Child Post Link and placed it on a parent post, and followed that link to the new Child post form to create a new child post of that parent post. When I submitted the form, the parent post was not linked to the child post unless I added a post relationship field in the Form contents. Your child post Form does not include such a post relationship field, so I would not expect the parent post to be linked in your site in the same scenario.

Upon further investigation, I saw some custom code snippets in Toolset > Settings > Custom Code (for example, the snippet edit-booth-1) that still reference the old post relationships system where a postmeta key "_wpcf_belongs_fair_id" was used to hold the ID of the parent post for a child post. That system of maintaining relationships via hidden custom fields is deprecated now, and cannot be relied upon for querying or establishing new relationships. Some backwards compatibility was built in, but after migrating relationships to the new system it is preferred to use the new post relationships system since new Booth posts will not be created with the old _wpcf_belongs_fair_id meta key, by default. During the relationship migration process, these code snippets containing _wpcf_belongs_fair_id should have prompted warnings, but it's possible those were overlooked. The new post relationships API should be used instead to query and set related posts programmatically:
https://toolset.com/documentation/customizing-sites-using-php/post-relationships-api/

So I suppose it could have been a remnant from the old relationships system, but it is no longer working with the new relationships system. Regardless, the solution moving forward is to add the required post relationship field to any Form that creates child posts, and update custom code snippets that reference the deprecated _wpcf_belongs_fair_id meta key to use the preferred Post Relationships API now. If you want to hide the post relationship field(s) on the front-end, use the custom HTML and CSS solution I presented in my previous comment to hide the field on the front-end of the site, but maintain the relationship implied when using the Create Child Link feature.

#1884219

Hi Christian,

Thank you for your help, I had no idea that the way it was set up was outdated. A few things:

1. To confirm, we need to add the fair_booth relationship field into this field and, going forward, any post forms with relationship need to have the respective relationship field added. Is it normal to have to hide this field? It seems like the old system was better in that this was not needed.

2. Can you provide what the preferred Post Relationships API code would be instead of the deprecated _wpcf_belongs_fair_id meta key? I am looking at the documentation https://toolset.com/documentation/customizing-sites-using-php/post-relationships-api/ and don't understand what should replace it.

I am guessing that the other meta keys we reference (wpcf-open-positions, wpcf-attendance-day, etc) are in correct as well?

3. Would edit post forms be affected? They seem to work, but perhaps the code for this is wrong as well?

#1888719

1. To confirm, we need to add the fair_booth relationship field into this field and, going forward, any post forms with relationship need to have the respective relationship field added. Is it normal to have to hide this field? It seems like the old system was better in that this was not needed.
Yes, this is correct. The parent post field is necessary. Hiding the field with CSS is acceptable: https://toolset.com/course-lesson/selecting-parent-posts-when-using-forms-to-create-child-items/

2. Can you provide what the preferred Post Relationships API code would be instead of the deprecated _wpcf_belongs_fair_id meta key? I am looking at the documentation https://toolset.com/documentation/customizing-sites-using-php/post-relationships-api/ and don't understand what should replace it.
There is no meta key replacement for establishing post relationships in the new system. Instead, to set a post relationship programmatically (for example, a child post form that does not include the parent post field), you must use the toolset_connect_posts API to connect two posts in the new relationships system:
https://toolset.com/documentation/customizing-sites-using-php/post-relationships-api/#toolset_connect_posts


I am guessing that the other meta keys we reference (wpcf-open-positions, wpcf-attendance-day, etc) are in correct as well?

No, Types fields have not changed. Only post relationships definitiions have changed. These fields you mentioned should remain as-is.

3. Would edit post forms be affected? They seem to work, but perhaps the code for this is wrong as well?
Edit post forms that do not modify post relationships are unchanged.

If you'd like to set up a test site where we can test all these changes out I'll be glad to review anything you have put together.

#1890763

I think we are using the _wpcf_belongs_fair_id meta key to get the id of the parent post (the fair post) of the created booth post. If we are trying to get the parent post id, rather than connect it to a child, shouldn't we use the toolset_get_parent_post_by_type API rather than the toolset_connect_posts API ?

If so, would the correct syntax be:
$booth= get_post( $booth_id ); $fair= toolset_get_parent_post_by_type( $booth, 'fair' );

#1890807

Yes, if you are "getting" instead of "setting" the parent post ID, you should use the toolset_get_parent_post_by_type API. You can use the Booth post ID directly in the first argument, so there is no need to call get_post. For example:

$booth_id = 12345; // example Booth post ID
$fair_id = toolset_get_parent_post_by_type( $booth_id, 'fair' );

The topic ‘[Closed] New Posts Created With Toolset Forms Not Connecting To Parent’ is closed to new replies.