Skip to content

Instantly share code, notes, and snippets.

@gabriele-carbonai
gabriele-carbonai / aux-functions.php
Created May 2, 2022 15:42 — forked from eduwass/duplicate-post.php
Programmatically duplicating a WordPress post
<?php
/**
* Duplicates a post & its meta and it returns the new duplicated Post ID
* @param [int] $post_id The Post you want to clone
* @return [int] The duplicated Post ID
*/
function duplicate($post_id) {
$title = get_the_title($post_id);
$oldpost = get_post($post_id);