Hi,
you can check if the hooks are being called by watching if the taxonomies or the custom fields are cloned with the post, as they are copied using the very hooks you’re mentioning…
How are you registering functions with the hooks? Is it a custom plugin or is it in your theme’s functions.php?
Thread Starter
furi3r
(@furi3r)
Hello @lopo
Yes, indeed it is duplicating all metadata associated with the custom post (including custom fields and taxonomy information)
I added the filter on functions.php (also on my custom plugin) but with no success:
add_action('dp_duplicate_post', 'test_clone', 90, 2);
add_action('dp_duplicate_page', 'test_clone', 90, 2);
function test_clone($new_post_id, $old_post_object)
{
add_post_meta($new_post_id, 'test_duplication', 1);
wp_mail( 'xxx', 'duplicate', 'duplication od' . $new_post_id);
}
NEither I get the email, neither test_duplication is added as metadata.
I tested different priorities to but same result.
Any idea?
Hi @furi3r,
I tested your code on a couple of sites but it looks like it’s working to me…
Can you check the error log of your server to look for any message that can be relevant?
Can you try to add the action with priority 5 instead of 90? (so it’s the first one called and if the others have any problems it’s already ended).
Thread Starter
furi3r
(@furi3r)
Hello Lopo
I think I’m missing something,
I went directly to the plugin and created the hook and still not working there.
Then I went to
duplicate_post_copy_post_meta_info
And commented out
//add_post_meta($new_id, $meta_key, duplicate_post_wp_slash($meta_value));
That I believe is where the meta data is added to the clone, and still is cloning the metadata…
Is there the metadata cloned somewhere else? Or I’m just becoming crazy, this is magic 😀
Hi @furi3r,
first of all, I’d recommend to update the plugin, I’ve released version 3.2 a few hours ago. While I don’t think it will solve the issue, one never knows…
Yes, that’s the line that copies the metadata, and there’s no other point in the code…
That’s quite a mystery!
Which custom post type are you trying to duplicate? Is it added by a plugin? If so, maybe the plugin has added its own duplicate feature? (For example, Woocommerce does)
Thread Starter
furi3r
(@furi3r)
You were right Lopo, my bad, that custom post type had integrated a duplicate option i was messing up with your plugin.
Please close the ticket and sorry for the inconveniences.
Hi!
Never mind, glad to hear it’s not my plugin’s fault 🙂