1. Home
  2. Developer’s guide
  3. Functions & Template tags
  4. duplicate_post_create_duplicate

duplicate_post_create_duplicate

Description

Creates a duplicate of the post object passed as the first parameter, according to the current settings except for status: the original status is copied by default unless a new status is explicitly specified.

Usage

<?php $new_post_id = duplicate_post_create_duplicate( $post, $status, $parent_id ); ?>

Parameters

  • $post
    • (int|WP_Post|null) post object to be cloned.
  • $status
    • (string) (optional) new status to set for the copy
      • Default: empty string
  • $parent_id
    • (integer) (optional) ID of the post to set as parent for the copy
      • Default: empty string

Return values

  • (int|WP_Error) The post ID on success. The value 0 or WP_Error on failure.