YEEESSS! That's it. I added a couple missing fields and saved it, you are good to go.
The generic fields at the end are styled differently than the regular post type fields, but I can fix that later I would assume.
I have inserted the form shortcode here, so you can test your code: lien caché
Minesh
Supporter
Les langues:
Anglais (English )
Fuseau horaire:
Asia/Kolkata (GMT+05:30)
Can you please check now:
I've added the following code to "Custom Code" section offered by Toolset "custom-code1":
=> lien caché
//Create a dynamic post title by the CRED form.
add_action('cred_save_data','func_combine_field_entries',10,2);
function func_combine_field_entries($post_id,$form_data) {
if ($form_data['id']==1243) {
$buch = $_POST['wpcf-bibelbuch'];
$chapter = $_POST['wpcf-chapter2'];
$verse = $_POST['wpcf-verse-from'];
$verse_to = $_POST['wpcf-verse-to2'];
//one verse or range?
$range = $verse;
if (!empty($verse_to)) {
$range .= '-'.$verse_to;
};
//concatenate title
$child_title= $buch. ' ' . $chapter .','. $range;
$child_slug = $post_id.'-'.$child_title;
// Child Post Args
$child_post_args = array(
'post_title' => $child_title ,
'post_name' => $child_slug ,
'post_status' => 'publish',
'post_type' => 'bible-verses', // Here you can put your child post type slug
);
// Insert the post into the database
$child_post_id = wp_insert_post( $child_post_args );
if( isset( $child_post_id ) && $child_post_id ) {
update_post_meta($child_post_id, 'wpcf-bibelbuch',$_POST['wpcf-bibelbuch']);
update_post_meta($child_post_id, 'wpcf-chapter2',$_POST['wpcf-chapter2']);
update_post_meta($child_post_id, 'wpcf-verse-from',$_POST['wpcf-verse-from']);
update_post_meta($child_post_id, 'wpcf-verse-to2', $_POST['wpcf-verse-to2']);
// connecting child post with parent
toolset_connect_posts( 'post-bible-reference', $post_id, $child_post_id );
}
}
}
And now I can see parent and child entry created automatically and connected as well.
The only thing you need to do is - you need to add all the select options for the field "Buch" you added here:
=> lien caché
You need to add the same options to your Generic select field "wpcf-bibelbuch". I've added 3 options, you need to add all remaining one.
Please check the following screenshot:
=> lien caché
Gald to help and finally happy to see your issue is resolved 🙂
This is great Minesh, you are a hero!! The form combination works and it saves to both post types - this is great.
This project calls for multiple bible verses to be added to one post. Is there a way to do that with like a generic repeater field?
Or would I have to put several copies of these fields on the form? I would have to put a hard limit on this relationship, which is not the intend, but still better than only having one bible reference:
1: Book Chapter Verse VerseTo
2: Book Chapter Verse VerseTo
3: Book Chapter Verse VerseTo
4: Book Chapter Verse VerseTo
5: Book Chapter Verse VerseTo
(It looks like a nightmare to enter all those bible books 5 times in the 5 different select fields)
Minesh
Supporter
Les langues:
Anglais (English )
Fuseau horaire:
Asia/Kolkata (GMT+05:30)
This project calls for multiple bible verses to be added to one post. Is there a way to do that with like a generic repeater field?
==>
No, there is no such option/feature available.
Or would I have to put several copies of these fields on the form? I would have to put a hard limit on this relationship, which is not the intend, but still better than only having one bible reference:
==> Yes, exactly, you need to add all child post fields 5 times if you want to create 5 entries at a time and you need to adjust the code accordingly.
My issue is resolved now. Minesh, you were most helpful. Thank you!