Skip to content

Instantly share code, notes, and snippets.

@kaskad88
Last active August 3, 2020 11:50
Show Gist options
  • Save kaskad88/132e9826515673c231d5452aebc43fb9 to your computer and use it in GitHub Desktop.
Save kaskad88/132e9826515673c231d5452aebc43fb9 to your computer and use it in GitHub Desktop.
add_action( 'jet-engine/forms/booking/notification/insert_post', function( $notification, $manager ) {
$form_id = absint( $manager->form );
if ( 1853 !== $form_id ) { // Need to change the Form ID
return;
}
$media_key = 'field_media2'; // Need to change the Media Field Name
if ( empty( $manager->data['inserted_post_id'] ) ) {
return;
}
if ( empty( $manager->data[ $media_key ] ) ) {
return;
}
$attachment_ids = explode( ',', $manager->data[ $media_key ] );
foreach ( $attachment_ids as $attachment_id ) {
wp_update_post( array(
'ID' => $attachment_id,
'post_parent' => $manager->data['inserted_post_id'],
) );
}
}, 20, 2 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment