Send email get_post_meta

Support General Send email get_post_meta

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #6300
    MikelMikel
    Participant

    Hello,I have a problem, after saving the entry I want to send an email. two email are sent correctly but $friendemail=get_post_meta( $post_id, 'alerta-emails', true ); is emprty.

    Thanks

    array(
    	'id' => $prefix . 'emails',
    	'type' => 'email',
    	'name' => 'Email',
    ),
    
    function send_mails_on_publish( $new_status, $old_status, $post_id)
    {
    	$post=get_post($post_id);
    	
        if ( 'publish' !== $new_status or 'publish' === $old_status
            or 'alertas' !== get_post_type( $post ) )
            return;
    	
    	$friendemail=get_post_meta( $post_id, 'alerta-emails', true );
    	
    	if( 'true' == get_post_meta( $post_id, 'alerta-emails', true ) )
            return;
    
        $author = get_userdata($post->post_author);
        $admin= get_bloginfo('admin_email');
        $emails      = array ($admin, $author->user_email, $friendemail);
        $alert = "Detalle". $post->post_title; 
        wp_mail( $emails, 'Nueva alerta publicada', $alert );
    }
    #6308
    Anh TranAnh Tran
    Keymaster

    Hi,

    I guess the problem is when you hook send_mails_on_publish. Probably it's hook too soon, sooner when Meta Box updates post meta.

    Currently Meta Box uses save_post_{$post_type} with priority = 10 to save post meta. You should hook after that (at save_post or at the same hook with higher priority).

    Looking at the function params, I think you're using transition_post_status. It's fired in wp_transition_post_status function that runs before save_post_* hook.

Viewing 2 posts - 1 through 2 (of 2 total)
  • The topic ‘Send email get_post_meta’ is closed to new replies.