Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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

share|improve this question
add comment

1 Answer

up vote 1 down vote accepted

it looks like you should use

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

instead of

$ogg = get_post($post->ID, post_title);
share|improve this answer
    
Yes, it works! Thanks :) –  She Hulk Feb 14 '13 at 19:39
    
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
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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