[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:
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?
Languages: English (English )Chinese (Simplified) (简体中文 )
Timezone: Asia/Hong_Kong (GMT+08:00)
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:
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...
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
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!