Whenever I post from the dashboard, I can grab the featured image URL with get_the_post_thumbnail_url() and display it in a email with wp_mail(). However, when I try this from the front-end, I get a empty URL.
Ive tried numerous frontend plugins but none works when it comes to the featured image. The rest of the post's fields display fine in the emails.
Im using the following code:
// POST MAILMAN
// Add the hook action
add_action('transition_post_status', 'send_new_post', 10, 3);
// Listen for publishing of a new post
function send_new_post($new_status, $old_status, $post) {
if('publish' === $new_status && 'publish' !== $old_status && $post->post_type === 'post') {
$latestPost_ID = $post->ID;
$latestPost_ImgUrl = get_the_post_thumbnail_url($latestPost_ID, 'full');
$latestPost_Category = get_the_category($latestPost_ID);
$latestPost_Category_Name = esc_html( $latestPost_Category[0]->name );
$latestPost_Url = get_post_permalink($latestPost_ID);
$latestPost_Title = get_post_field( 'post_title', $latestPost_ID );
$latestPost_Excerpt = get_post_field( 'post_excerpt', $latestPost_ID );
$todaydate = date("l") . ", " . date("j") . " " . date("F") . " " . date("Y");
to display the image in the email:
<td class="fluid-img" style="font-size:0pt; line-height:0pt; text-align:left;"><img src="' . esc_url($latestPost_ImgUrl) . '" border="0" width="650" height="366" alt="" /></td>
When done front-end vs backend: https://imgur.com/a/TqP9L6a
Some plugins I tried: https://wordpress.org/plugins/accesspress-anonymous-post/ https://wordpress.org/plugins/wp-user-frontend/
$recent_posts = wp_get_recent_posts( array( 'numberposts' => '1' ) );
?$latestPost_ID
it should be$latestPost_ID = $post->ID;
– Sky