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']
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"
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.
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
My issue is resolved now. Thank you!
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');
Thanks for sharing the solution, it will help other users.