Skip Navigation

[Resolved] Preselect parent in childpost form

This support ticket is created 2 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 – 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 2 replies, has 2 voices.

Last updated by Thorworx 2 years, 2 months ago.

Assisted by: Luo Yang.

Author
Posts
#2509741

Tell us what you are trying to do?
Preselect parent in childpost form

I have done many searches of the documentation, but most results are very old, and many of the solutions seem to be hidden in the support threads.

What is the link to your site?
hidden link

I've created a CRED form to add new child posts to a CPT parent. This form will display ON the parent CPT page (and maybe in a View loop).
I have a relationship field that was inserted via the relationship field in the Form Wizard.
This generated the following code in the form:

<label for="%%FORM_ID%%_@competition-entry-competition-entry-rating.parent">[cred_i18n name='@competition-entry-competition-entry-rating.parent-label']Competition Entry[/cred_i18n]</label>
			[cred_field field='@competition-entry-competition-entry-rating.parent' class='form-control' output='bootstrap' select_text='--- not set ---' required='true' author='$current' urlparam='parent_competition-entry_id']

(I've switched to the advanced form editor, and don't think I can switch back to the wizard without losing manual changes I've made). I tried doing this manually in a hidden field, but was not successful.
The above wizard code generates a drop-down select that works fine for creating the child post relationship, but I just need to have this field value pre-selected (and hidden - I know I can hide it with CSS).

It would seem that it should be easy to change this select to a single (hidden) field, but I'm not seeing how to do it.

#2510151

Hello,

Please try to replace the shortcode you mentioned above from:

[cred_field field='@competition-entry-competition-entry-rating.parent' class='form-control' output='bootstrap' select_text='--- not set ---' required='true' author='$current' urlparam='parent_competition-entry_id']

To:

[cred_field field='@competition-entry-competition-entry-rating.parent' class='form-control' output='bootstrap' select_text='--- not set ---' required='true' author='$current' urlparam='parent_competition-entry_id' value='[wpv-post-id item="$current_page"]']

and test again

More help:
https://toolset.com/documentation/programmer-reference/forms/cred-shortcodes/#cred_field
value. Optional. Preset value
https://toolset.com/documentation/programmer-reference/views/views-shortcodes/item-attribute/
$current_page is used to retrieve data from the current page being rendered.

#2510429

Thanks Luo. That works perfectly.