Skip Navigation

[Gelöst] How can I set the value by default?

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

Problem:

How to setup default value in the relationship field of child post form?

Solution:

You can follow our document to setup the child post form link, and pass an URL parameter to the child post form, and setup the default value:

https://toolset.com/course-lesson/selecting-parent-posts-when-using-forms-to-create-child-items/#creating-forms-when-a-parent-post-is-preselected

section "Creating Forms with a Parent Post Preselected"

Relevant Documentation:

This support ticket is created vor 2 Jahre. 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.

No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.

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 6 Antworten, has 2 Stimmen.

Last updated by Luo Yang vor 2 Jahre.

Assisted by: Luo Yang.

Author
Artikel
#2329207

Hi Luo,

It also works fine on hidden link but 1 question:

How can I set the value by default? Like at the messages form?
This is what I have:
[cred_field field='@antiquair-artikel.parent' class='form-control' output='bootstrap' select_text='--- not set ---' author='$current']

#2329211

Hello,

Please elaborate the questions with more details:
Which parent post do you want to set as default value?

The URL you mentioned above, it is a WordPress page, you can follow our document to setup the child post form link, and pass an URL parameter to the child post form, and setup the default value:
https://toolset.com/course-lesson/selecting-parent-posts-when-using-forms-to-create-child-items/#creating-forms-when-a-parent-post-is-preselected
section "Creating Forms with a Parent Post Preselected"

#2329403
select.JPG

Hi Luo,

The connection is working fine once the parent is filled in manually. In this case the parent post is the antiquair.
But it would be great if this antiquair could be filled in automatically. Then the user (the antiquair) will no longer have to do it.
The field could then be set to hidden. The antiquair should be determined as follows. It is the one with the same author as the currently logged in user.

Note that this extra complexity arises from the inability to have relationships between custom post types and users. Otherwise we would just have added some fields to the user table and the user id would have been sufficient to define a relationship. But now everything is based on the existence of 1 antiquair custom post per user.

#2329833

You just need to follow the document I mentioned above:
https://toolset.com/course-lesson/selecting-parent-posts-when-using-forms-to-create-child-items/#creating-forms-when-a-parent-post-is-preselected

Display a child form link in single "antiquair" post, it will pass the URL parameter to child post form, and setup the parent post automatically

#2330361

My issue is resolved now. Thank you!

#2331523

Hi,

I have solved this with a shortcode [antiquair]:

function antiquair_shortcode() {
global $wpdb;
$uid = get_current_user_id();
$sql = "
SELECT $wpdb->posts.*
FROM $wpdb->posts
WHERE $wpdb->posts.post_status = 'publish'
AND $wpdb->posts.post_type = 'antiquair'
AND $wpdb->posts.post_author = $uid
ORDER BY $wpdb->posts.ID
";
$results = $wpdb->get_results($sql, OBJECT);
$antiquair = empty($results) ? 0 : $results[0]->ID;
return $antiquair;
}
add_shortcode('antiquair', 'antiquair_shortcode');

#2333193

Thanks for sharing the solution, it will help other users.

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