I am trying to include a rating comment meta value in the subject line of the email that notifies authors that someone has left a new comment (and, in my case, a rating) on their post.
function mycustomfilter_comment_notification_subject( $subject, $comment_id ) {
$comment = get_comment( $comment_id );
$subject = get_the_title( $comment->comment_post_ID ) . ': ' . get_comment_meta( $comment->comment_ID, 'rating', true ) . ' star rating';
return $subject;
}
add_filter( 'comment_notification_subject', 'mycustomfilter_comment_notification_subject', 10, 2 );
The get_comment_meta()
call is failing. It also fails when I try and output the same comment meta data using the comment_notification_text filter
.
The rating value is being saved to the database as I can access this variable in a custom wp_list_comments()
callback I have prepared.
Any idea why my email code is failing? Many thanks.
$comment->comment_ID
inget_comment_meta( $comment->comment_ID, 'rating', true )
is unnecessary as you already have the$comment_id
variable from the filter so you should use that there instead:get_comment_meta( $comment_id, 'rating', true )
. Same inget_the_title()
I guess. Might help.