Tribe__Repository::save( $return_promise = false )
{@inheritdoc}
Source
File: src/Tribe/Repository.php
public function save( $sync = true ) {
$ids = $this->get_ids();
if ( empty( $ids ) ) {
return array();
}
$exit = array();
$postarrs = array();
foreach ( $ids as $id ) {
$postarr = array(
'ID' => $id,
'tax_input' => array(),
'meta_input' => array(),
);
foreach ( $this->updates as $key => $value ) {
if ( is_callable( $value ) ) {
$value = $value( $id, $key, $this );
}
if ( ! $this->can_be_udpated( $key ) ) {
throw Tribe__Repository__Usage_Error::because_this_field_cannot_be_updated( $key, $this );
}
if ( $this->is_a_post_field( $key ) ) {
if ( $this->requires_converted_date( $key ) ) {
$this->update_postarr_dates( $key, $value, $postarr );
} else {
$postarr[ $key ] = $value;
}
} elseif ( $this->is_a_taxonomy( $key ) ) {
$postarr['tax_input'][ $key ] = $value;
} else {
// it's a custom field
$postarr['meta_input'][ $key ] = $value;
}
}
$postarrs[ $id ] = $postarr;
}
// @todo actually implement async
foreach ( $postarrs as $id => $postarr ) {
$this_exit = wp_update_post( $postarr );
$exit[ $id ] = $id === $this_exit ? true : $this_exit;
}
return $exit;
}