Question

I set an email button in functions php. The email is sent when clicking on a front-end update post button. The problem is: the email is sent but I can't get the post title to appear in the post. I guess I didn't correctly set the post_title variable... Anyway, here's the code (taken and partially edited from a old wp answers thread).

For the button

function show_publish_button2(){
Global $post;
    echo '<form name="front_end_publish" method="POST" action="">
            <input type="hidden" name="pid" id="pid" value="'.$post->ID.'">
            <input type="hidden" name="FE_PUBLISH" id="FE_PUBLISH" value="FE_PUBLISH">
            <input type="submit" name="submit" id="submitp2" value="" onClick="return confirm(\'are you sure?\')">
        </form>';
}

for updating the post and emailing

if (isset($_POST['FE_PUBLISH']) && $_POST['FE_PUBLISH'] == 'FE_PUBLISH'){
if (isset($_POST['pid']) && !empty($_POST['pid'])){
update_post_meta((int)$_POST['pid'], 'rivedi_check', 'false');
$ogg = $post->post_title;
    $to = 'email@adress.com';
$subject = 'Post updated';
$message = 'Post title '.$ogg;
        wp_mail(
            $to,
            $subject,
            $message
        );
 }
}

I also tried with:

$ogg = get_post($post->ID, post_title);

But it's the same, it doesn't work. The only thing that is written in the email body I receive is: "Title of the post: ".

No correct solution

Licensed under: CC-BY-SA with attribution
Not affiliated with wordpress.stackexchange
scroll top