Skip to content

Instantly share code, notes, and snippets.

@gaambo
Created May 4, 2020 08:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gaambo/410003ba9127171dc1b3e7adf9122aeb to your computer and use it in GitHub Desktop.
Save gaambo/410003ba9127171dc1b3e7adf9122aeb to your computer and use it in GitHub Desktop.
Duplicate Elementor Templates with Duplicate Post Plugin (WordPress)
// when duplicating a elementor template elementor save_post hook get's fired before all the post meta is duplicated
// and elementor sets the template type to the default page --> popups cannot be dupliated
// so the elementor key is removed from duplicating and duplicatd manually later on
add_filter('duplicate_post_meta_keys_filter', function ($keys) {
if ($k = array_search('_elementor_template_type', $keys)) {
array_splice($keys, $k, 1);
}
return $keys;
});
add_action('dp_duplicate_post', function ($newPostId, $originalPost) {
$elementorTemplateType = get_post_meta($originalPost->ID, '_elementor_template_type', true);
update_post_meta($newPostId, '_elementor_template_type', $elementorTemplateType);
}, 11, 2); // prio 11 after duplicating
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment