acf_field_taxonomy::save_post()publicACF 5.0.9

This function will save any terms in the save_post_terms array

Метод класса: acf_field_taxonomy{}

Хуков нет.

Возвращает

null. Ничего (null).

Использование

$acf_field_taxonomy = new acf_field_taxonomy();
$acf_field_taxonomy->save_post( $post_id );
$post_id(int) (обязательный)
-

Список изменений

С версии 5.0.9 Введена.

Код acf_field_taxonomy::save_post() ACF 6.0.4

function save_post( $post_id ) {
	// Check for saved terms.
	if ( ! empty( $this->save_post_terms ) ) {
		/**
		 * Determine object ID allowing for non "post" $post_id (user, taxonomy, etc).
		 * Although not fully supported by WordPress, non "post" objects may use the term relationships table.
		 * Sharing taxonomies across object types is discouraged, but unique taxonomies work well.
		 * Note: Do not attempt to restrict to "post" only. This has been attempted in 5.8.9 and later reverted.
		 */
		$decoded = acf_decode_post_id( $post_id );
		$type    = $decoded['type'];
		$id      = $decoded['id'];

		if ( $type === 'block' ) {
			// Get parent block...
		}

		// Loop over taxonomies and save terms.
		foreach ( $this->save_post_terms as $taxonomy => $term_ids ) {
			wp_set_object_terms( $id, $term_ids, $taxonomy, false );
		}

		// Reset storage.
		$this->save_post_terms = array();
	}
}