Hai.
Had the same issue.
And found this link to do it myself:
https://bay-a.co.uk/wordpress-tips/gravity-forms-custom-post-from-form/
Happy coding 😉
Thanks for this. I had seen it before but skipped over it. I’ll have to try again.
Looks like it skips GF+CPT plugin which is probably what I need to do.
When using this solution, you indeed do not need this plugin…
I have implemented it myself now with the function shown below.
It can be used by any form, you don’t need to use the form id.
It checks whether there is a post_id defined in the entry.
Next, it checks all fields supplied whether the value contains an existing post_type.
In the form itself, I used a dropdown field to enable the user to select the post_type. Make sure that the values of the dropdown correspond with the post_types defined.
/**
* Use a custom post type if defined by a field in the form
*
*/
public function wps_gf_set_post_type($entry, $form) {
// Get the post_id if it exists
if (isset($entry['post_id'])) {
$post_id = $entry['post_id'];
} else {
return;
}
// Check the values of the form fields
if (isset($form['fields'])) {
foreach ($form['fields'] as $field) {
if (isset($entry[$field['id']])) {
// Get the value entered for this field
$entry_value = $entry[$field['id']];
// If an existing post_type is found, then use it for this post
if (post_type_exists($entry_value)) {
set_post_type($post_id, $entry_value);
return;
}
}
}
}
}
Thank you so much. Will try it out in the next few days.
This is my frustration with GF that they don’t provide useful snippets like this. I guess they rely on the community to provide the answers.