ACF_Internal_Post_Type::duplicate_post
Duplicates an ACF post.
Метод класса: ACF_Internal_Post_Type{}
Хуки из метода
Возвращает
Массив
. The new ACF post array.
Использование
$ACF_Internal_Post_Type = new ACF_Internal_Post_Type(); $ACF_Internal_Post_Type->duplicate_post( $id, $new_post_id );
- $id(int|строка)
- The ID of the post to duplicate.
- $new_post_id(int)
- Optional post ID to override.
Список изменений
С версии 6.1 | Введена. |
Код ACF_Internal_Post_Type::duplicate_post() ACF Internal Post Type::duplicate post ACF 6.4.2
public function duplicate_post( $id = 0, $new_post_id = 0 ) { // Disable filters to ensure ACF loads data from DB. acf_disable_filters(); $post = $this->get_post( $id ); if ( ! $post || ! $post['ID'] ) { return false; } // Update attributes. $post['ID'] = $new_post_id; $post['key'] = uniqid( 'group_' ); // Add (copy) to title when appropriate. if ( ! $new_post_id ) { $post['title'] .= ' (' . __( 'copy', 'acf' ) . ')'; } // When importing a new field group, insert a temporary post and set the field group's ID. // This allows fields to be updated before the field group (field group ID is needed for field parent setting). if ( ! $post['ID'] ) { $post['ID'] = wp_insert_post( array( 'post_title' => $post['key'] ) ); } $post = $this->update_post( $post ); /** * Fires immediately after an ACF post has been duplicated. * * @date 12/02/2014 * @since 5.0.0 * * @param array $post The ACF post array. */ do_action( "acf/duplicate_{$this->hook_name}", $post ); return $post; }