Skip to content

Commit b550b31

Browse files
authored
gpnf-add-child-entry-on-render.php: Fixed issue where new entry ID was not populated on render.
1 parent 48862fa commit b550b31

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

experimental/gpnf-add-child-entry-on-render.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,21 @@
1717
// Update "1" to any field ID from your child form and "Second Choice" the value that should be saved to this field.
1818
'1' => 'Second Choice',
1919
// Update "2" to another field ID in your child field and "Second" to the value that should be saved to it.
20-
'2' => 'Second',
20+
'2' => time(),
2121
// Add as many "field ID" => "value" pairs as required.
2222
), $parent_form['id'] );
2323

2424
$session = new GPNF_Session( $parent_form['id'] );
25+
26+
// Attach new child entry to the session.
2527
$session->add_child_entry( $child_entry_id );
2628

29+
// Get all entry IDs from the session and return them.
30+
$session_entry_ids = $session->get( 'nested_entries' );
31+
if ( ! empty( $session_entry_ids[ $nested_form_field->id ] ) ) {
32+
$entry_ids = $session_entry_ids[ $nested_form_field->id ];
33+
}
34+
2735
return $entry_ids;
2836
}, 10, 3 );
2937

0 commit comments

Comments
 (0)