ACF_Field_Group::delete_postpublicACF 6.1

Deletes an ACF field group and related fields.

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

Хуки из метода

Возвращает

true|false.

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

$ACF_Field_Group = new ACF_Field_Group();
$ACF_Field_Group->delete_post( $id );
$id(int|строка)
The ID of the field group to delete.

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

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

Код ACF_Field_Group::delete_post() ACF 6.4.2

public function delete_post( $id = 0 ) {
	// Disable filters to ensure ACF loads data from DB.
	acf_disable_filters();

	// Get the post.
	$post = $this->get_post( $id );

	// Bail early if post was not found.
	if ( ! $post || ! $post['ID'] ) {
		return false;
	}

	// Delete the fields.
	$fields = acf_get_fields( $post );
	if ( $fields ) {
		foreach ( $fields as $field ) {
			acf_delete_field( $field['ID'] );
		}
	}

	// Delete post and flush cache.
	wp_delete_post( $post['ID'], true );
	$this->flush_post_cache( $post );

	/**
	 * Fires immediately after an ACF post has been deleted.
	 *
	 * @date 12/02/2014
	 * @since 5.0.0
	 *
	 * @param array $post The ACF post array.
	 */
	do_action( "acf/delete_{$this->hook_name}", $post );

	return true;
}