I am trying to write a plugin that copies a custom post type “event” from one blog to another. The code for copying I already have working but I cannot seem to get this “add_action” hook to work when an event is published.

add_action('publish_event', 'copy_event_to_mini_site' );

function copy_event_to_mini_site() {

code in here to copy relevant data from one blog to the other

}

I also tried: add_action('publish_post', 'copy_event_to_mini_site' );

That did not work either.

3 Answers
3

Read the codex, that’s where i finally found the answer :

https://codex.wordpress.org/Plugin_API/Action_Reference/publish_post

in the end :

Custom Post Types

To trigger this action for a custom post type, use publish_{$custom_post_type}. e.g. if your post type is ‘book’ use:

add_action( 'publish_book', 'post_published_notification', 10, 2 );

Leave a Reply

Your email address will not be published. Required fields are marked *