Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle saving related values if passed as an array of information #4917

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions classes/PodsAPI.php
Original file line number Diff line number Diff line change
Expand Up @@ -5444,6 +5444,33 @@ public function save_pod_item( $params ) {
}
} elseif ( $is_file_field && isset( $v['id'] ) ) {
$v = (int) $v['id'];
} elseif ( 'pods' === $data_mode && ! isset( $v[0] ) ) {
// Save related field values.
$v_id = false;

if ( isset( $v[ $search_data->field_id ] ) ) {
$v_id = $v[ $search_data->field_id ];

unset( $v[ $search_data->field_id ] );
}

if ( ! empty( $v_id ) ) {
$search_data->save( $v, null, $v_id );
} else {
$row_has_values = array_filter( $v );

if ( ! $row_has_values ) {
continue;
}

$v_id = $search_data->add( $v );
}

if ( empty( $v_id ) ) {
continue;
}

$v = $v_id;
} else {
continue;
}
Expand Down