0

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: ".

1

it looks like you should use

$mypost = get_post($_POST['pid']);
$ogg = $mypost->post_title;

instead of

$ogg = get_post($post->ID, post_title);
| improve this answer | |
  • ok great, good luck with your project ;-) – birgire Feb 14 '13 at 19:48
  • i definitely need it :P – She Hulk Feb 14 '13 at 19:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.