0

I create a custom post type and I insert programmatically a new post of that type with wp_insert_post with draft status.

I need to send and email when in backend the post is published so I used publish_post but seems the callback function is not executed, can help me please?

    function post_published_notification( $ID, $post ) {
    /* code for testing purpose only */

    $postarr = array(
            'post_content' => 'fake content ' . $post_id,
            'post_title' => 'fake title ' . $post_id,
            'post_type' => 'gdpr_qao',
        );

    wp_insert_post( $postarr );
}
add_action( 'publish_post ', $plugin_admin, 'post_published_notification', 10, 2 );
  • There's a trailing space in the action name. Is that a copy/paste error, or is that in the original? And what's $plugin_admin here - the object you're trying to call post_publish_notification on? That syntax looks wrong. – Rup May 3 '19 at 10:16
  • I found the error: I'm using a custom post type called gdpr_qao so the correct action name must be publish_gdpr_qao and not generic publish_post... Thank you! – user164608 May 3 '19 at 10:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy