Skip Navigation

[Gelöst] Difficulty Storing Related Post

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

Heute stehen keine Supporter zur Arbeit im Werkzeugsatz-Forum zur Verfügung. Sie können gern Tickets erstellen, die wir bearbeiten werden, sobald wir online sind. Vielen Dank für Ihr Verständnis.

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)

Dieses Thema enthält 47 Antworten, hat 4 Stimmen.

Zuletzt aktualisiert von Shane vor 5 Jahren, 5 Monaten.

Assistiert von: Shane.

Author
Artikel
#904358
temp.jpg

I am trying to get my forms to work with the new relationships and am having difficulty on one of them. The form is meant to allow a user to post a link to a product review to be associated with a particular product listing, and it is set to have a status "Pending" upon submission. Here is the relevant code on the form:

[credform class='cred-form cred-keep-original']

	<div class="hidden">[cred_field field='@product-listing_product-review-ext.parent' urlparam='productid' class='hidden' output='bootstrap']</div>

	[cred_field field='form_submit' value='Submit' urlparam='' class='btn btn-primary btn-lg' output='bootstrap']

[/credform]

When loading the form, it appears to be correctly selecting the parent product because when I un-hide the div section I can see that it is selected. Upon form submission, the following code is run:

  add_filter('cred_success_redirect_328', 'custom_redirect_for_form_with_id_328', 10, 3);
  function custom_redirect_for_form_with_id_328( $url, $post_id, $form_data )
  {
	$relationship_to_query = "product-listing_product-review-ext";
	$role = "parent";
	$related_post = toolset_get_related_post( $post_id, $relationship_to_query, $role);
  	$newurl = get_permalink($related_post);
	return $newurl;
  }

I was expecting the post to be added and to be redirected to the parent product listing. However, the toolset_get_related_post is returning 0 instead of the expected parent post type ID. When going into the database, I do not see any records being written to the toolset_associations table. In the WordPress back end, I can see the review as being added with pending status but there is no association with the parent product.

Attached are screenshots from the toolset_relationships table so you can see the slug being used. This relationship is set as a one-to-many with the product listing being able to take infinite reviews.

Thanks for any help. Feeling stuck.

- Aaron

#904464

Max

Aaron,
I have the same problem. I think this will be fixed next week in version 2.0

https://toolset.com/forums/topic/automatically-set-post-parent-in-post-form-from-url-parameter/page/2/

#904587

Hi Christian,

If I'm understanding you correctly, then that's a bit of a bummer. I have a lot of forms and they almost all use relationships. Am I hearing you right that the only way to avoid having my users submit two separate forms in order to create one post that's in a relationship with another is to use the custom code? I'd rather not have to create custom code for every single form, but if this is the only way then of course I'll do it.

Did I read correctly in the other thread that once the latest version of Toolset Forms is released that the custom code will still be required?

- Aaron

#904599

I apologize, I read the information on that incorrectly. Let me clarify, and I will remove my previous answer. The new Forms system will allow you to define a parent relationship in a new child post form without the need for any custom code, and the Forms code you showed in the example above seems fine. In your custom success redirect callback, it appears that the toolset_get_related_post API does not retrieve the parent post's ID when the child post's status is pending review:

$related_post = toolset_get_related_post( $post_id, $relationship_to_query, $role);

Can you temporarily change the child post's status to "published" to confirm this is the issue you're experiencing? If the redirect happens as expected after changing the post status, then I can try to get more information about this from the developers.

#904662

Hi Christian,

No worries - thanks for clarifying. I changed the post status to published and it still doesn't seem to be recording the parent post ID. The redirect callback returns 0 as the related post ID and viewing the new post in the admin console doesn't show it being linked to the parent post.

- Aaron

#904668

- Was this post relationship migrated from the legacy system, or created in the new system?
- What is the status of the parent post you are trying to attach this child post to?
- Is this CRED form creating new child posts, or editing existing child posts?
- What setting is selected in the CRED form for "What to show after submitting the form"?

#905125

- Migrated from legacy system
- Parent post is published
- Form is for creating a new post
- After submission, the form is set to redirect to the login page, but I'm using a success redirect to return them to the parent post's page

#905204

Shane
Supporter

Sprachen: Englisch (English )

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

Hi Aaron,

Christian is currently having a public holiday to but he will be here tomorrow to continue with this ticket. However it is already known that if the post is not publish from the form then the parent information won't be set.

#905543

Okay thank you for the additional information. If the redirect isn't working after modifying the child post status to be "Published" when the form is submitted, then something else must be going on. I'll need to take a closer look. I can log in and create a clone of the site, or I can work from a clone of the site you create. Let me know how you would like to proceed. I will activate private reply fields here.

#905832

In my local testing, I was able to determine that the problem seems to be related to Layouts. I have disabled the Template Layout for the Private Page "Add an External Review" on your site, and you can see the results of a test here:
versteckter Link
The parent post was selected appropriately. The redirect isn't working, but that's because of the debug code in place in the Code Snippet here. Can you update the Code Snippet and confirm this is working as expected? If so, then I can escalate the Layout conflict to my 2nd tier team for further investigation.

#905852

I can confirm the form is now submitted correctly for me, although it's not using the proper layout and it's setting the status to publish instead of pending.

- Aaron

#906151

Okay thank you, I have escalated this to my 2nd tier support team for further investigation and will update you here when I have more information to share.

#907909

Hi - Just checking in on this. Do you have any updates on when relationships will store properly when their post status is set to pending? Now that I've migrated everything over to the new relationships, this is becoming a persistent problem through multiple areas of my website and I've got just a couple of weeks to go until I launch. Thanks in advance.

- Aaron

#907958

I can see that our developers have marked this as a critical issue, and have a fix proposed. I cannot confirm yet whether or not this will be available in the next update, but I think in all likelihood it will. However, I do not have a timeline available for that just yet.

Could we work around the issue by setting the form to "publish" the post rather than pending review, then in the success redirect after getting the related post ID, modify the post status to "pending"? Let me know if that could work and I can try to add that to the success redirect callback.

#907986

Hi Chrstian,

That's a good idea. I just gave it a test manually and even though it drops the association while it's set to pending, it does remember it when switching back to published. I will look into making a temporary snippet that changes it to pending after saving the data. Thanks.

- Aaron