I'm using the following to send an email to the admin when a post is publish by an author:
add_action('publish_post', 'send_admin_email'); function send_admin_email($post_id){
$to = '[email protected]';
$subject = 'subject';
$message = "Here is :".get_permalink($post_id);
wp_mail($to, $subject, $message );
I would like to add the post author in $message
.
I try get_the_author();
and the_author();
but nothing happens.
I'm using the following to send an email to the admin when a post is publish by an author:
add_action('publish_post', 'send_admin_email'); function send_admin_email($post_id){
$to = '[email protected]';
$subject = 'subject';
$message = "Here is :".get_permalink($post_id);
wp_mail($to, $subject, $message );
I would like to add the post author in $message
.
I try get_the_author();
and the_author();
but nothing happens.
1 Answer
Reset to default 1Missing global ?
global $post;
No global variable available if you are using publish_post action hook!
Ref : http://hungred/how-to/tutorial-post-id-publishpost-action-hook-wordpress/
Update 2 :
or try this
$author = get_userdata($post->post_author);
So you can use $author
where you will :D