WPML
SignaturePHP
do_action( 'wpml_admin_make_post_duplicates', int $master_post_id )

Description

Builds or updates duplicate posts from a “master” post. You can call it from admin screens, REST requests and WP-CLI.

Arguments

  • $master_post_idintRequired

    The ID of the post to duplicate from. It can be that of a post, page or custom post. The “master post” doesn’t need to be in the default language.

Example Usage

PHP
// this will create duplicates for the "Hello World!" post
do_action( 'wpml_admin_make_post_duplicates', 1 );

In the example below, we create duplicates of a post, page or custom post the first time it is published. It works in the block editor, the classic editor and WP-CLI.
A more advanced examplePHP
add_action( 'wp_after_insert_post', 'my_duplicate_on_publish', 10, 4 );
function my_duplicate_on_publish( $post_id, $post, $update, $post_before ) {
	// Only a published post. Skip revisions and autosaves.
	if ( wp_is_post_revision( $post_id ) || wp_is_post_autosave( $post_id ) || 'publish' !== $post->post_status ) {
		return;
	}

	// Skip a post that already has translations or duplicates.
	// This also stops the loop when WPML saves the duplicates.
	if ( apply_filters( 'wpml_element_has_translations', false, $post_id, $post->post_type ) ) {
		return;
	}

	// Remove this callback while WPML creates the duplicates, then add it again.
	remove_action( 'wp_after_insert_post', 'my_duplicate_on_publish', 10 );
	do_action( 'wpml_admin_make_post_duplicates', $post_id );
	add_action( 'wp_after_insert_post', 'my_duplicate_on_publish', 10, 4 );
}