Skip Navigation

[Gelöst] Parent Post isn’t selected automatically

Dieser Thread wurde gelöst. Hier ist eine Beschreibung des Problems und der Lösung.

Problem:

Pass default value to parent selector of post form for creating child post.

Solution:

You can pass the default value as shortcode attribute, for example:

https://toolset.com/forums/topic/parent-post-isnt-selected-automatically/#post-1136656

Relevant Documentation:

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

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

Dieses Thema enthält 6 Antworten, hat 2 Stimmen.

Zuletzt aktualisiert von marcialB vor 6 Jahren, 1 Monat.

Assistiert von: Luo Yang.

Author
Artikel
#1134501
links.PNG

Hi there

I have a post type called styleguide that has several one-to-many relationships to add logos, colors, images and so on to the styleguide.

I created forms to create child posts with a parent post selector. That is working. However, it's never preselecting the parent. According to this post here https://toolset.com/documentation/post-relationships/selecting-parent-posts-using-forms-create-child-items I assumed, that would work automatically. I have both tried opening the form with a link from the styleguide (the form is embedded on a normal page) and as a modal on the styleguide-page itself (inserted in the layout). Both times the parent isn't preselected. In fact in the modal the parent field doesn't show anything anyways. But as it's not even working on the page with the form for the child post, I assume I forgot something anyways.

In case it helps, here is one styleguide we created (its a work in progress so it's a bit messy): versteckter Link. At the bottom, there are two links to test (if you need an account, let me know).

Thanks for your help.

Best,
Marcial

#1134880

Dear Marcial,

I assume you are displaying a Toolset form for creating child post in the single parent post.

If it is, you can setup the default value by setting "value" attribute of parent selector shortcode [cred-field], for example:
[cred_field value="[wpv-post-id]" ...]

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

#1136634

Hi Luo

I'm afraid I need some help with this.

Option 1 (Popup): This is the shortcode in the popup window: {!{cred_form form='logo'}!}. Now you suggest to add a value like this {!{cred_form form='logo' value='...'}!}? What value is the current ID (must be dynamic) and how can I connect that with the parent post selector in the form?

Option 2 (link to page): I added the parameter like this: versteckter Link (75 is the ID of my styleguide). That doesn't work. Also "-1" doesn't work. Changing it to "?parent_toolset-api_id=..." didn't work (as shown in the example).

Can you help me with this?

Thanks,
Marcial

#1136656

In a single "styleguide" post, you can get the "styleguide" post ID with Views shortcode [wpv-post-id]:
https://toolset.com/documentation/user-guides/views-shortcodes/#wpv-post-id

And in a single "styleguide" post, you can display the Toolset post form for creating "logo" post.

In the Toolset post form for creating "logo" post, section "Content", find and edit the shortcode [cred_field] for rendering the parent selector, you can pass [wpv-post-id] as attribute "value", for example:

[cred_field field="@RELATIONSHIP-SLUG.parent" value="wpv-post-id" class="form-control" output="bootstrap" select_text="--- not set ---"]

#1136703

Hi Luo

Awesome, I was able to get the modal to work.

For the second attempt (form is on a separate page), I am able to pass the parent ID with the URL like this:

versteckter Link;

However, even though it resolves correctly (to 75 in this case), on the new page it preselects "logo erfassen", what is the page title instead of the relationship. I assume there is something wrong with the URL generated.

Best,
Marcial

#1137352

You can get the URL parameter "wpv-post-id" value with shortcode [wpv-search-term], for example:
[wpv-search-term param="wpv-post-id"]
versteckter Link

Then pass it to form shortcode [cred_field], like this:

[cred_field field="@RELATIONSHIP-SLUG.parent" value='[wpv-search-term param="wpv-post-id"]'class="form-control" output="bootstrap" select_text="--- not set ---"]
#1137429

My issue is resolved now. Thank you!