Support » Plugins » Send mail when a post is published

  • Hello guys
    I want to implement a function which, when a new post is created , controls all the request-posts (post_type=request, which is a post type I created in my WP site), and if the new post (post_type=post) has some custom fields equals to the request-post that is created before, then it just send a mail to an email address.

    Until now, I’ve implemented this in the functions.php, but with no results:

    function wpr_authorNotification($post_ID) {
       $post = get_post($post_ID);
       $manufacturer=get_post_meta($post->ID, 'Manufacturer', true);
       $message = "
          Hi ".echo get_post_meta($post->ID, 'wpcf-request_client_name', true).",
          Your post, ".$post->post_title." has just been published. Well done!
    global $request;
    $args = array( 'post_type' => 'requests', 'post_status'=> 'publish' );
    $myrequests = get_posts( $args );
    foreach( $myrequests as $request ) {
    if (  $manufacturer == get_post_meta($request->ID, 'wpcf-article-manufacturer', true)  )
    mail(get_post_meta($request->ID, 'wpcf-request_client_email', true), "Your article is online", $message);
    add_action('publish_post', 'wpr_authorNotification');

    How can I change the code?

  • The topic ‘Send mail when a post is published’ is closed to new replies.