Skip Navigation

[Resolved] Set Automatically Parent Child Relationship in Reviewing System

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

Problem:

I am trying to create a Reviewing System for a 'Parent CPT'. I have created a 'Child CPT for Reviews' and a 'Child CPT for Reviews Post Form' which, among others, contains a selector for the 'Relationship Parent CPT - Child CPT for Reviews'. I have added the 'Child CPT for Reviews Post Form' on the 'Layout for Parent CPT', but you still have to select the Parent manually. The Parent post is not automatically preselected as I thought it would be as per supporting documentation.

Solution:

Yes, it is possible to setup the current parent post as default value of the relationship field, you just need to setup the "value' attribute as current post ID: [wpv-post-id id="$current_page"], for example:

https://toolset.com/forums/topic/set-automatically-parent-child-relationship-in-reviewing-system/#post-1209832

Relevant Documentation:

https://toolset.com/documentation/user-guides/cred-shortcodes/#cred_field

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

Supporter timezone: Asia/Hong_Kong (GMT+08:00)

This topic contains 5 replies, has 2 voices.

Last updated by andrei-laurentiuP 5 years, 7 months ago.

Assisted by: Luo Yang.

Author
Posts
#1209800

Tell us what you are trying to do?

I am trying to create a Reviewing System for a 'Parent CPT'. I have created a 'Child CPT for Reviews' and a 'Child CPT for Reviews Post Form' which, among others, contains a selector for the 'Relationship Parent CPT - Child CPT for Reviews'. I have added the 'Child CPT for Reviews Post Form' on the 'Layout for Parent CPT', but you still have to select the Parent manually. The Parent post is not automatically preselected as I thought it would be as per supporting documentation.

Also, the Searching for Parent / Selector for Parent within the 'Child CPT for Reviews Post Form' runs very slowly (even 10 seconds for only a couple of Parent Options) - is there any way to improve the speed with which it searches for Parent Post Types in cases when the user has to select the Parent?

Is there any documentation that you are following?
https://toolset.com/documentation/post-relationships/selecting-parent-posts-using-forms-create-child-items/
https://toolset.com/documentation/getting-started-with-toolset/publish-content-from-the-front-end/forms-for-creating-content/

Is there a similar example that we can see?

What is the link to your site?

#1209832

Hello,

Yes, it is possible to setup the current parent post as default value of the relationship field, you just need to setup the "value' attribute as current post ID: [wpv-post-id id="$current_page"], for example:

Edit the post form for creating child post, in section "Form editor", find and edit the relationship field shortcode, add attribute:
value='[wpv-post-id id="$current_page"]' in it, like this:

[cred_field ...  value='[wpv-post-id id="$current_page"]']

More help:
https://toolset.com/documentation/user-guides/cred-shortcodes/#cred_field

value. Optional. Preset value

Then you can use CSS codes to hide it, see the document you mentioned above:
https://toolset.com/documentation/post-relationships/selecting-parent-posts-using-forms-create-child-items/#creating-forms-when-a-parent-post-is-preselected
Screenshot:
hidden link

And it should be able to improve the speed, since you don't need to search/choose options in it.

#1209855

It works well. My issue is resolved now. Thank you!

#1209861

Sorry, just another quick question. Is there any other relatively easy option apart from writing CSS to completely hide the field? With CSS it can easily be disabled from inspector + someone could use it to post reviews for a post where they should not be allowed to...

#1209867

I don't think there is other easy to completely hide the field, you might consider custom PHP codes, for example:

1) Add a generic hidden field into the post form for creating child post.
https://toolset.com/documentation/user-guides/inserting-generic-fields-into-forms/
Use current parent post ID as the default value of hidden field.

2) After user submit the post form, use action hook "cred_save_data" to trigger a custom PHP function, in this function, do these:
a) Get the generic hidden field value(Parent post ID):
hidden link

b) Connect the new "Child" with specifc "Parent" post with function "toolset_connect_posts"
https://toolset.com/documentation/customizing-sites-using-php/post-relationships-api/#toolset_connect_posts

If you need more assistance for it, new ticket please.

#1209869

Thanks, it's a good start. My issue is resolved now. If I will have further questions regarding my php custom code I will open a new ticket. Have a great day! Thank you!

This ticket is now closed. If you're a Toolset client and need related help, please open a new support ticket.