get_post_meta returning no value in custom post type alert email

I am working on a function that will alert a user via email when a custom post type (glossary_post) has been created on the frontend of my site. It is working well except I need to get the value of a CPT (glossary_tag) to print out in the message of the email and it is returning nothing. My code:

add_action( ‘transition_post_status’, ‘pending_post_status’, 10, 3 );

function pending_post_status( $new_status, $old_status, $post ) {

$author_id=$post->post_author;
$address = get_the_author_meta(‘user_login’, $author_id);
$user_id = get_current_user_id();
$user_info = get_userdata($user_id);
$edit_author = $user_info->user_login;
$post_id = $post->ID;
$post_cat = get_post_meta( $post_id, ‘glossary_tag’, true);

if ( ( $new_status === “pending” ) && ( $post->post_type == ‘glossary_post’ ) ){

$post_title = $post->post_title;
$to = ‘XXXXXX.com’;
$subject = ‘A Glossary term has been created’;
$message = ‘A new Glossary term named “‘ . $post_title . ‘” has been created in the category “‘ . $post_cat . ‘” by ‘ . $address . ‘. Please login at XXXXX to review and then publish if acceptable.’;

wp_mail( $to, $subject, $message );
}

}

I have tried changing $post_cat = get_post_meta( $post_id, ‘glossary_tag’, true); to false at the end and that returns “Array”. Each post can only have 1 glossary_tag so I’m not sure what I am doing wrong. As it is now it just returns “”.

Read more here:: get_post_meta returning no value in custom post type alert email

Leave a Reply

Your email address will not be published. Required fields are marked *